# Event Handler problems MC Button issues

**URL:** <https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826>\
**Category:** flash\
**Created:** [July 26, 2004, 3:08pm UTC](https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826 "2004-07-26T15:08:02Z")\
**Posts on this page:** 4\
**Page:** 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:** [July 30, 2004, 3:44pm UTC](https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826/21 "2004-07-30T15:44:01Z")

</div>

> [@jillymo](#):
>
> Stringy- I am trying to put this code you so graciously provided me into words so that I can completely understand why it makes what I needed done work. I understand the basic idea but anyway without more bable here is what I am getting out of it:
> 
> //mcs labelled mystate0,mystate1 etc  
> //swfs to load called movie0.swf,movie1.swf etc  
> [COLOR=Navy][SIZE=1]createEmptyMovieClip(“container”, 5);  
> [COLOR=DarkRed]for (var i = 0; i\<52; i++) {  
> this[“myState”+i].ivar = i;[/COLOR]  
> this[“myState”+i].onPress = function() {  
> loadMovie(“movie”+this.ivar+“.swf”, “container”);  
> this.enabled = false;  
> };  
> }[/SIZE][/COLOR]
> 
> :book: An empty movie clip called container is created on level 5 of my main movie. Now I know what this stuff in the middle (in red)does, but it’s explaining the exactness of the code that gets me. There is a variable and if it is less than 52, than an increment is added…which allows each state to be pressed once, in turn calling the function which loads an swf into the container mc, and once a state has been pressed it is disable.
> 
> Anyway, I know this is what happens but know it is missing some explanation. If you could fill in the exact words/process for me I would be so happy.

I think actually you explained it better than i can.  
we are looping throught the sequence 52 times(from i=0 to i=51 inclusive) and each time a value of 1 is added to i.On the first loop, i will be 0, so the next line gives us this[“myState”+0].ivar = 0;

this - refers to the timeline, so you may well be able to replace with \_root but later if you decide to load the movie into another it will cause you problems.  
[“myState”+0] just refers to the movieclip myState0  
its as if “this” or (\_root) is an array and flash knows to look in “this” for the stuff inside the square brackets which it is what it is looking for.  
ivar is a property we have given each mc and in this case it has a value of 0.  
you can call ivar whatever you want,it doesn`t matter.  
like saying Object.property=value  
So each mc has a property ivar but they are all unique values making them useful.  
The next line gives us  
this[“myState”+0].onPress = function() {  
loadMovie(“movie”+this.ivar+“.swf”, “container”);  
//in other words (movie0.swf,“container”)  
this.enabled = false;  
};

inside a callback function “this” refers to whatever is calling the function not to the timeline as you might expect. So this just means(on our first loop)  
myState0.enabled = false;

Then it does the whole thing again with 1 etc.

---

<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:** [July 30, 2004, 3:51pm UTC](https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826/22 "2004-07-30T15:51:49Z")

</div>

Thanks AGAIN Stringy. It seems so easy once the code is written and explained. I just wonder when I will ever get to the point when I will be able to work through these things on my own and be able to write the script myself. I would have made this such a long process never realizing that it could all be addressed with one block of script rather than basically doing the same thing over and over for each mc. I just hope one of these days the lightbulb finally comes on…

😃

---

<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:** [July 30, 2004, 3:59pm UTC](https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826/23 "2004-07-30T15:59:55Z")

</div>

> [@jillymo](#):
>
> Thanks AGAIN Stringy. It seems so easy once the code is written and explained. I just wonder when I will ever get to the point when I will be able to work through these things on my own and be able to write the script myself. I would have made this such a long process never realizing that it could all be addressed with one block of script rather than basically doing the same thing over and over for each mc. I just hope one of these days the lightbulb finally comes on…
> 
> 😃

We have all been there Jillymo but you are doing the right thing in trying to understand code rather than just copy it blindly. Once you have used it a couple of times you`ll wonder what all the fuss was about.

---

<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:** [July 30, 2004, 4:01pm UTC](https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826/24 "2004-07-30T16:01:46Z")

</div>

_L_ I hope so!

[Previous page](https://forum.kirupa.com/t/event-handler-problems-mc-button-issues/58826.md?page=1)
