MX frame events / vars question

i’ve got this code inside the MC that i’m attaching to the stage:

this.onLoad=function(){
	//myName=this._name;
	//trace(myName);
	myColor = new Color(this);
	myColor.setRGB(0xff0000);
	
}
this.onLoad();

this.onEnterFrame=function(){
	myColor.setRGB(0x0000aa);
}

why doesnt’ this work? is it not seeing the vars named in onLoad because they’re name inside a function? i’m still fuzzy on this part of MX…
thanks in advance,
-mojo

  1. You are using two onLoads. you only need one.

  2. You actually don’t need the onLoad :slight_smile:

myColor = new Color(this);
myColor.setRGB(0xff0000);
this.onEnterFrame = function() {
	myColor.setRGB(0x0000aa);
};

Also… why are you defining one color constantly onEnterFrame? you should just set that as the original color…

myColor = new Color(this);
myColor.setRGB(0x0000AA);

so you just declare the new colors in AS and don’t need them in onLoad to init them? if this is so, why use onLoad at all? like i said, i’m still trying to figure the MX method out…

the reason for the enterFrame is that i’ll be changing the color dynamically, having it get its value from an array that i’m generating.

one thing i haven’t been able to figure out are listeners and how to subscribe events to variables–could you please explain this?
thx,
-mojo

onLoad is when you are loading things in dynamically usually.

Things like loadVars(), XML(), etc use it to detect if the file is loaded.

And you don’t need an onEnterFrame to dynamically change a color. You can just define a function that gets called on when the color is changed.

Check my attachment to see my babbling in action.

er…when i try to download it, my system reads it as ‘attachment.php’ and can’t grok the filetype (i’m running explorer on osx.2)???

Ok, I .zipped it then. It should work now.

And as for Listeners… I learned about them from the AS dictionary…

http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/

Just look for addListener, next to that they will tell you how to use listeners with these methods…

FStyleFormat.addListener, Key.addListener, Mouse.addListener, Selection.addListener, Stage.addListener, TextField.addListener.

got it…thanks for the pointers :goatee:

No problem :slight_smile: I hope they help you out :slight_smile:

One thing: onLoad doesn’t work so well. There’s a fix in the Best Of Kirupa forum. But as Lost said, you don’t need it here :slight_smile:

Oh wow, I didn’t know there was a bug with onLoad, thanks for pointing that thread out Ilyas, definitely taught me something :slight_smile: