PDA

View Full Version : How to dynamically give MC an instance names?



ecptavares
April 13th, 2008, 07:58 PM
Now I have this code which is loading all the images from the xml file into a container and I need to set some ID to track which image should be opened bigger in another MC.
And I also need to use this ID to when user hovers mouse over an image it scales up a little using tweener.



private function loadThumbs():void
{
for(var j:uint = 0; j < thumbs.length ;j++)
{
MC = new MovieClip();
MC.name = "number " + j;
MC.x = j * thumbsSize;
imgLoader = new Loader();
imgLoader.load(new URLRequest(thumbs[j]));
MC.addEventListener(MouseEvent.CLICK, onClick);
MC.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
MC.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
MC.addChild(imgLoader);
container.addChild(MC);
}
addChild(container);
}



When I trace MC.name at onClick event it shows the instance name.

How should I do?

nikefido
April 13th, 2008, 08:32 PM
depends on how you are setting them up.

For the image that is being moused over and what not, you can just use "event.Target" or "event.currentTarget" -

if your MC's are named with a numbering scheme, you can using "int(myMC.name) - 1" to get the MC "next to" the image being moused over (if that's how you set them up).

Another way is to use the getChildAt() method to get a child at the current MC's index, and then add or subtract an index value to get other MC's. This isn't a bullet-proof way to deal with it, however.

ecptavares
April 14th, 2008, 07:17 AM
Can You send me some examples please!?

Here is what I am trying to do with the onMouseOver and onMouseOut events :

www.restaurantegraciliano.com.br