Mc event handlers in MX

hi-
i’m trying to make the paradigm shift to MX’s movie clip event handers–here’s where i’m stuck:
first, i’m dynamically attaching MCs for my menu:

menuArray = [“current”, “play”, “mfa”, “resume”, “contact”];

this.onLoad = function () {
mLen =menuArray.length;
//add menuMCs to stage ////
for (i=0; i<mLen; i++){
level=i+10;
myName=menuArray*;
attachMovie(“MENU_MC”,myName,level);
//set init properties for each loaded MC
setProperty(myName, _x, markerX);
myW=getProperty(myName, _width);
myX=markerX+(i*myW);
setProperty(myName, _x, myX);
setProperty(myName, _y, 200);
setProperty(myName, _alpha, 80);
}
}

second, inside each mc is this code:

myName=this._name;

this.onMouseUp = function () {
trace(myName);
//_root.loadMenuMC(myName);
}

when i mouse up, each Name is traced, so it seems that this function is being activated in every menu MC that is loaded, and each is calling loadMenuMC with its name as the variable. i also tried this syntax:

myName.onMouseUp=
and _parent.myName.onMouseUp

so how do i differentiate the ‘generic’ MC function calls?

also, bonus points for telling me how variables can be passed from onLoad to onEnterFrame, etc. it seems when i tried it that the onEnterFrame didn’t pick up any vars from onLoad.

any help in figuring this problem out and info on mc event handlers in general is much appreciated–
regards,
-mojo

First off, if you are using MX, you want to be certain that you are utilizing the correct syntax for actionscript. setProperty() is one of those deprecated functions that really shouldn’t be used unless it is entirely necessary for speed issues (and it won’t be supported in future versions of the Player most likely)

Second, when you define the onLoad() for a MovieClip and that onLoad event is not on the actual clip (it’s code in the clip or on a frame), you need to call the onLoad() handler to instantiate the changes you’ve made.

Example, when a MovieClip is loaded into memory, the onLoad event is called … before any code is executed inside the clip itself. So, redefining the onLoad() handler inside the clip will result in nothing, because onLoad is only called one time.

Changing what you had to MX style, and noting that your for() loop was wacked out in your post … wrong number of arguments…


menuArray = ["current", "play", "mfa", "resume", "contact"];

this.onLoad = function () {

   mLen = length(menuArray); // faster to use length()

   for (i=0; i < mLen; i++) {

      myName=menuArray*;
      attachMovie("MENU_MC", myName , i*10);
      this[myName]._x = markerX + i * this[myName]._width;
      this[myName]._y = 200;
      this[myName]._alpha = 80;
      
      // Add in your onMouseUp handler to each clip

      this[myName].onMouseUp = function() {
         trace(_name);
      }

   }
}

// instantiate the onLoad() redefinition

this.onLoad();


To answer your bonus question, variables will be loaded into a clip if the onLoad() handler is defined in the AS panel when you have the clip selected (not AS inside the clip). If the onLoad() handler is defined inside the clip, you need to instantiate it after redefining it, as I mentioned above.

cheers.

thanks for your reply, jb–i’ve been going thru your response and here are some of my questions, observations, etc.

i’m doing everything via attachMovie, so i don’t have any MCs w. external AS coding–instantiating did the trick afa the onLoad problem–thanks!

so this is the preferred way of setting a property in MX?
this[myName]._y = 200;
this method of naming confuses me–the brackets make it look like its referencing an array, but whatever, i’ll use it.

also, it looks like you got rid of my named variables by just referencing the property directly? that’s cool, for some reason whenever i tried this in F5, it didn’t always work, but ‘get.set property’ always worked, so i used it instead. anyway, this is better, because you’re cutting out extra lines of code–ok i’ll buy into it

also, when i try to use your method here, it returns the wrong number ???
mLen = length(_level0.menuArray); // faster to use length()
//returns 31 -wrong
mLen = _level0.menuArray.length;
//returns 5-correct
trace(mLen);

This is the main part of my problem, i think:

i don’t understand this part inside the onLoad function in the code you wrote–is it assigning that function to the mouseUp action in the MC its attaching?

 // Add in your onMouseUp handler to each clip
  this[myName].onMouseUp = function() {

this may be part of my problem–it seems that the ‘select’ var (which holds the section lection var) isn’t being passed from one MC to another, even though one is calling the other directly.

the other main problem is that everytime i hit the mouseDown on one button, every one of the MC btns activates as well–i get a value return for each one.
here is the BTN script that i’m calling with:
this.onMouseDown = function () {
attachMovie(“Sub_MenuOO”, subMenu, 50);
_root.section=myName;
}

sorry for the length, i’ve been wading thru this all afternoon–it’s definitely looking a lot better already–thanks again for helping me out on this!
regards,
-mojo