# MX frame events / vars question

**URL:** <https://forum.kirupa.com/t/mx-frame-events-vars-question/13163>\
**Category:** flash\
**Created:** [February 9, 2003, 9:06pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163 "2003-02-09T21:06:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mojoNYC](https://avatars.discourse-cdn.com/v4/letter/m/b5a626/32.png) [@mojoNYC](https://forum.kirupa.com/u/mojoNYC)\
**Post date:** [February 9, 2003, 9:06pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/1 "2003-02-09T21:06:06Z")

</div>

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

```php
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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2003, 9:14pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/2 "2003-02-09T21:14:53Z")

</div>

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

2. You actually don’t need the onLoad 🙂

```php
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…

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2003, 9:27pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/3 "2003-02-09T21:27:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2003, 11:26pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/4 "2003-02-09T23:26:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2003, 11:37pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/5 "2003-02-09T23:37:21Z")

</div>

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)???

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 9, 2003, 11:45pm UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/6 "2003-02-09T23:45:28Z")

</div>

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/](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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 12:11am UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/7 "2003-02-10T00:11:55Z")

</div>

got it…thanks for the pointers :goatee:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 3:53am UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/8 "2003-02-10T03:53:19Z")

</div>

No problem 🙂 I hope they help you out 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 8:24am UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/9 "2003-02-10T08:24:17Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [February 10, 2003, 8:33am UTC](https://forum.kirupa.com/t/mx-frame-events-vars-question/13163/10 "2003-02-10T08:33:15Z")

</div>

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