Looping through movieclips with FOR loop ???

  • Chuck le Moche
  • Newbie
  • Newbie
  • User avatar
  • Posts: 5
  • Loc: Montréal, Québec, Canada

Post 3+ Months Ago

Hi everybody,

First time post, but you'll se a lot of me in the futur.

I need some help for something probably very easy, since I don't find any explanation for it anywhere (surely its so easy no one ever taught it would need an explanation).

I have 4 components (smart buttons) on stage, named respectively bM1, bM2, bM3 and bM4. They have a width property that can be access with bMn._w. I need to access them all in turn, reposition them depending on the stage size. I've got all the stage listener stuff working fine, absolutely no prob there.

My problem is: how can I access the movieclips? I tried:
Code: [ Select ]
for (var i=1;i<=4;i++){
   var target='bM'+i;
   trace(target);  //this gives me bM1,bM2,bM3 and bM4
   trace(target._w) //gives me "undefined"
            //but
   trace(bM1._w)   //gives me 62, which is good
};
  1. for (var i=1;i<=4;i++){
  2.    var target='bM'+i;
  3.    trace(target);  //this gives me bM1,bM2,bM3 and bM4
  4.    trace(target._w) //gives me "undefined"
  5.             //but
  6.    trace(bM1._w)   //gives me 62, which is good
  7. };


My approach is certainly wrong, and for months now I had to work around this in other ways. But I know now enough OO programing to know it must be possible.

Please HELP ME !!! (scream of despair)

Chuck le Moche
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Voetsjoeba
  • Novice
  • Novice
  • User avatar
  • Posts: 31
  • Loc: Belgium, Ghent.

Post 3+ Months Ago

You can place your buttons in one movieclip, and then use this:

Code: [ Select ]
for (all in movieclipcontainingbuttons){
   trace(movieclipcontainingbuttons[all]._w)
};
  1. for (all in movieclipcontainingbuttons){
  2.    trace(movieclipcontainingbuttons[all]._w)
  3. };


That should do it.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Note:

The problem with your original code is in the target variable.

'bM'+i will return a string value that is just bM1, bm2, bM2. But what you are looking for is the instance name of a clip within a certain timeline. For that you will need to use associative array referencing. For example...

Code: [ Select ]
this['bM'+i]


or if the clips are within another clips timeline

Code: [ Select ]
clipInstanceName['bM'+i]


For more information on this check this out....

http://www.kirupaforum.com/forums/showt ... adid=12082





Voetsjoebas method is probably the metter method of the two. It will loop through a timeline using a for...in loop and find your clips.

For more information on for...in loops check out this tutorial...

http://www.kirupa.com/developer/actions ... /forin.htm



Hope this helps :D
  • Chuck le Moche
  • Newbie
  • Newbie
  • User avatar
  • Posts: 5
  • Loc: Montréal, Québec, Canada

Post 3+ Months Ago

FINALLY ! ALLELUIA!!!!

I've never got through this question, and finally I got an answer.

Thank you so much!! :D

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.