Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

targetting movie clips via variable 2

Status
Not open for further replies.

Thoe99

Programmer
May 11, 2001
119
US
I have an movie clip inside another movie clip that I want to target a variable on the main timeline.

I have a stated variable "graphic" on the first frame of the main timeline. There are four buttons (actually they are movie clips, with a button inside them) on the main timeline, named "button_one", "button_two" and so on.

When any of them are clicked, it will set variable "graphic" equal to "one", "two", "three", "four" (for example). Within the movie clip (MCA) on the main timeline, there's a movie clip (MCB). I want to be able to target one of the four buttons, via the variable "graphic", like "button_four" or "button_two". The "four" or "two" is the variable "graphic," so it is an extension of the targetted name. How would I go about doing that?

~happy new years
 
A bit confusing question.
If you define your variable as _root.graphic = false; , or even better as _level0.graphic = false; , on the first frame of the main movie...
And then from your buttons (in movie clips, or in loaded movies on another level) you change that value to something else as:

BUTTON 1...
on(press){
_level0.graphic = "button_one";
}

Then you can use if statements in the main movie or within the button's code itself as:

on(press){
_level0.graphic = "button_one";
if(_level0.graphic == "button_one"){
_root.gotoAndStop(10);
}

Regards,
wink4.gif
ldnewbie
 
This helps a lot, but the second part of my question was if there was a way to use a variable to extend a tell-target name.

For example...if graphic did become "one," can I make it to where I tell target button_"graphic" as an expression?
 
Still some confusion for me...
First off the tellTarget action is deprecated in Flash 5, you can simply use the dot syntax instead, and in this case, if I understand you correctly, probably an "associative array" scripting.

So, supposing graphic = "one";
You could use...

_root["graphic"].gotoAndStop(10);

Or...

_root["graphic"]._x = whatever;

Does that help?

Regards,


wink4.gif
ldnewbie
 
How do you know when to use double = and when to use single = for variables? And when do you use _root as opposed to _level0?
 
I think adding a basic example is the best thing I can do in this case. The example, of course, doesn't work yet.


In the main timeline, there are 3 named movieclips, each has a button inside. The bottom button is the "activator" button, which tells the top three buttons, which frame of the mc to goto.

The "associative array" is exactly what I'm trying to get to work right.
 
Single = is for setting a variable like x = 10; or x ="test";
Double == is for comparison like in if statements...
if (x == "test"){
do_something;
} else {
do_something_else;
}

Having a look at your .fla now.

Regards,
wink4.gif
ldnewbie
 
No offense BBD... But a lot more coding in your solution, for basicly the same result!

And Thoe99, you might want to change that "number" variable to something like "my_number" or whatever else, because "number" is pretty close to "Number", which is a function in Flash. Typos could lead to errors!

Regards,
wink4.gif
ldnewbie
 
Ah....thanks a lot! This is exactly what I was looking for. Actually, BigBadDave's is closer to what I have in mind, hehe. I'll show you my new site, once it's done.
 
Yeah but old,
My code is not exactly long and its all dynamic you only need 2 movie clips not 30 or wotever. Regards

Big Bad Dave

davidbyng@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top