Tuesday, February 19, 2008

MovieClip(root)

MovieClip(root).doStuffLikeNormal_rootInAS2

This is what makes AS3 still programmable, but I wish they wouldn’t force you to cast it to MovieClip. That’s just stupid. More and more as I program with AS3 it feels like it’s full of poor choices of syntax. I mean, why do you have to do that whole addEventListener every time that you want to make a simple button? I understand that they’re trying to centralize code, but come on. Sometimes if its just a tiny function, it’s BETTER to have it on a button isntead of clogging up the main frame.

Why did they take away var on textboxes? Why did they take away eval? Meh…

Posted by johnfn at 22:07:15 | Permalink | Comments (2)

Monday, February 4, 2008

This is just annoying me.

MovieClip.prototype.bringToTop = new function(){
    this.parent.setChildIndex(this, this.parent.numChildren-1);
}

The whole “access a mc by its parent only” thing gets to me sometimes.

Posted by johnfn at 22:37:31 | Permalink | No Comments »

Thursday, September 13, 2007

AS3: Frame Labels

if (mc.currentLabel == “Start”)

I find this really helpful. It goes a bit more towards the ideal fully flexible Flash movie/game that can have its frames adjusted at will.

Posted by johnfn at 20:57:26 | Permalink | No Comments »

Wednesday, September 12, 2007

Push Array

AS3: My open source “push array”.

What does it do? It stores things inside an array. You add to the array by going array.Push(Obj) and pop from the array by doing array.Pop(Obj).

 What would I use it for? Lets say you have a space shooter game. Enemies are constantly flying in and out of the game. In order to hit test them properly with bullets and without (much) lag, you would create a push array and push all enemies that exist into the array. Whenever one dies or flies off screen, you pop it from the array.

 

(This class is not optimized. I’ll probably put up a faster one later that counts the number of objects in the array instead of just going straight to 200. Still, I think it might be helpful.)

package {
    import flash.filters.*;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.display.*;
    import flash.events.MouseEvent;

    public class pushArray {
        var base:Array = new Array(200);
        function pushArray() {
            for (var i:int=0; i<200; i++) {
                base[i]=undefined;
            }
        }
        public function Find(obj:Object):int {
            for (var i:int=0; i<200; i++) {
                if (base[i]==obj) {
                    return i;
                    break;
                }
            }
            return -1;
        }
        public function Push(obj:Object):int {
            for (var i:int=0; i<200; i++) {
                if (base[i]==undefined) {
                    obj.index=i;
                    base[i]=obj;
                    return i;
                    break;
                }
            }
            return -1;
        }
        public function Get(index:int):Object {
            return base[index];
        }
        public function PopIndex(index:int) {
            base[index]=undefined;
        }
        public function Pop(obj:Object) {
            for (var i:int=0; i<200; i++) {
                if (base[i]==obj) {
                    base[i]=undefined;
                    break;
                }
            }
        }
        public function getArray():Array {
            var real:Array = new Array();
            var indx:int=0;
            for (var i:int=0; i<200; i++) {
                if (base[i]!=undefined) {
                    real[indx++]=base[i];
                }
            }
            return real;
        }
        public function len():int {
            var len:int;
            for (var i:int=0; i<200; i++) {
                if (base[i]!=undefined) {
                    len++;
                }
            }
            return len;
        }


        public function Hit(obj:Object):Object {
            for (var i:int=0; i<200; i++) {
                if (base[i]!=undefined && base[i]!=obj) {
                    if (obj.hitTestObject(base[i])) {
                        return base[i];
                    }
                }
            }
            return false;
        }


        public function Trace() {
            var vals:String = “”;
            for (var i:int=0; i<base.length; i++) {
                if (base[i]!=undefined) {
                    vals = vals + ” ” + base[i];
                } else {
                    vals = vals + ” undef”;
                }
            }
            trace(vals);
        }
    }
}

Posted by johnfn at 20:39:28 | Permalink | Comments (3)

Ridding MCs.

AS3: Getting rid of movie clips.

As far as I know, there IS NO WAY. No way to perminently delete it from Flash, anyways. The best you can hope for is clearing every existing variable that references to the clip, then going removeChild(clip) and deleting all listeners that listen for the clip (because they keep an instance of the clip).

Posted by johnfn at 20:33:23 | Permalink | Comments (2)

Tuesday, September 11, 2007

AS3 quips

 

AS3:

 

e.currentTarget

When you add an event listener, and then do something like this:

function listen(e:Event){

e.target.x+=5;

}

 

That could actually screw you up. For some dumb reason e.target doesn’t actually always return the target movie clip. ?!?! I don’t understand you, Adobe.

The correct way is of course e.currentTaret.x+=5;

 

getChildIndex()

Weirdly enough, you cant just do

getChildIndex(e.currentTarget);

 

You have to do… (deep breath)

e.currentTarget.parent.getChildIndex(DisplayObject(e.currentTarget))

 

 

Posted by johnfn at 00:10:22 | Permalink | No Comments »

Monday, September 10, 2007

I’m a cool kid

I want to test out this thing cause it seems so cool. Plus, all the cool kids are doing blogs nowadays.

Posted by johnfn at 02:59:01 | Permalink | No Comments »