PDA

View Full Version : Playing an MC using a variable for instance name


Thom Phelps
07-24-2006, 11:17 PM
Basic, basic stuff, but having some trouble.

On the main timeline I have one movie clip that has several stops within it. At the beginning of the MC, I stop the main timeline and let the MC play. Each time the MC comes to a stop it prompts the viewer to click the "next" button to continue. When I come to the end of the MC, I stop the MC and play the Main timeline ( _root.play(); ), which in some cases advances the main timeline to the next keyframe where another (different) MC plays and the process starts all over again (main timeline is stopped while the MC plays. Each time the MC stops, it prompts the user to click the "next" button, etc.)

My "next" button is on the main timeline and it tells the MC to play:

on (release) {
MC_instancename.play();
}

Currently, I have a different instance of the "next" buttton for each MC instance, but what I want to do is have one instance of the "next" button and just have it play whichever MC is currently on the timeline.

So I created a variable called currentClipPlaying_mc and at the beginning of the given MC, I set this variable to be the instance name of the movie clip:

_root.currentClipPlaying_mc = this._name;
_root.stop();


It seems simple enough that all I need to do with my "next" button is tell it to play the MC instance name that I've assigned to the variable currentClipPlaying_mc. Which I thought would be:

on (release) {
_root.currentClipPlaying_mc.play();
}

So, for example, if the instance name of the MC is "exampleOne_mc", and I've used _root.currentClipPlaying_mc = this._name; that makes currentClipPlaying_mc = exampleOne_mc. Doesn't this mean that by saying this:

on (release) {
_root.currentClipPlaying_mc.play();
}

I'm actually saying this:

on (release) {
_root.exampleOne_mc.play();
}

Or do variables not work in a path?

mapvnfx
07-25-2006, 04:31 AM
Hi :D

as I see in your codes:

_root.currentClipPlaying_mc is just a string (the value of mc._name is string too).

if you want to check this, use
trace(typeof(_root.currentClipPlaying_mc));

you can fix your prob by using eval() function:
_root.currentClipPlaying_mc = eval("_root." + this._name); // be careful with the path :D

Thom Phelps
07-25-2006, 03:15 PM
Thanks! That worked great.

sophistikat
07-25-2006, 03:59 PM
eval() has been deprecated; you should be using path[variable].property = valueon (release) {
_root[_root.currentClipPlaying_mc].gotoAndPlay(1);
}

Thom Phelps
07-25-2006, 05:21 PM
Hmmm.. trying to get this to work, but... can't find any reference in Flash help or the Adobe knowledgebase.
Do I need to use the path[variable].property = value in the MC when assigning the MC instance name to currentClipPlaying_mc in addition to using it in the button's on (release) as in your AS example?

In MC:
_root[_root.currentClipPlaying_mc]._name = this._name

?