Welcome to WebmasterWorld Guest from 54.211.17.91

Forum Moderators: open

Message Too Old, No Replies

Similar Variable Names

movieclip1, movieclip2, movieclip3

   
3:19 am on Jan 26, 2010 (gmt 0)

5+ Year Member



Hello. Does anyone know how to have flash Action Script check for movieclips with similar names? Here is an example:


if(movieclip1._y==theothervariable){
}
if(movieclip2._y==theothervariable){
}

But condensed similar to an array?:

var checking = 1;
while (checking<3){
if(movieclip[checking]==theothervariable){//This is the part that I am not sure on.
//The other code
}
checking++;
}

Any help would be greatly appreciated!

7:59 pm on Jan 26, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Regular expressions is available in AS, but I wouldn't use that approach. I'd **probably** (depending on context) lay down a reliable method of naming, and follow it. For example, let's say, using XHTML, you import a video playlist. The .flv's can be any name, at any time, but when you import them you put all references into an array, something like

(standard Flash CML import/parse, then as you look through the XML nodes)
images[k]=image;
captions[k]=cap;

Which assigns them an index in the array.

So now when you create movie symbol names,

for (i=0;i<images.length;i++) {
moviename= 'moviename'+i;
}

And you'd access and parse the movie symbols the same way.

1:08 am on Jan 27, 2010 (gmt 0)

5+ Year Member



So now that I have the moviename variable: "moviename1",how can I put it into my script? For example, how can I find the _x axle of it? Thank you!
3:28 am on Jan 27, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



for (i=0;i<images.length;i++) {
moviename= 'moviename'+i;
trace(eval('_root.'+moviename+'._x'));
}

Would be my first guess. Honestly, off the top, don't know, I'd have to get in and play with it.

I use eval there because I've had some come-and go problems with dynamically named movie symbols, the specifics are sadly absent, also due to having too much stuff crammed in my head. :-\

4:28 am on Jan 27, 2010 (gmt 0)

5+ Year Member



Great, thanks!
2:42 am on Jan 28, 2010 (gmt 0)

5+ Year Member



How can I make it so that that movieclip will go forward a frame?


eval('_root.'+moviename+'.nextFrame()');

That doesn't work: Do you know what would? Thank you!

5:16 am on Jan 28, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I think you want something like goToAndPlay() or goToAndStop().

eval('_root.'+moviename+'.goToAndPlay(5)');

Should start on frame 5.

11:22 pm on Jan 28, 2010 (gmt 0)

5+ Year Member



Hmmm.... that doesn't seem to work.
6:22 pm on Jan 29, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



As said, I'd have to play with it, not sure if I'm helping or diverting . . .

Tray eval only on the name, like

var obj = eval('_root.'+moviename);
obj.goToAndPlay(1);

3:13 am on Jan 30, 2010 (gmt 0)

5+ Year Member



SetProperty seems to be working