Flash Q.
- Started
- Last post
- 18 Responses
- fate
Ok, let's say I want to target an MC multiple times in a chunk o' code. But to reuse the code, I want to make the MC I target a variable at the beginning and then reference that variable throughout my chunk o' code. How do I do that?
- fate0
and yeah I know the basics, I'm just having a hard time finding how to reference a variable like...
variableName.gotoAndStop(#);
- karlj0
yeah dude
var mcTarget = "myClip";
this[mcTarget].gotoAndStop(2);
say you have a clip named myClip. that should do that trick.
karl
- fate0
no, that's not going to work. One of the first things I tried. The code wouldn't even read like that because you left out a period after "this" and it assumes myClip is nested within "this"
- unfittoprint0
_global.MC = myMC;
- UndoUndo0
you don't need a "." after this when used in that way.
myClip =Hellraiser;this[myClip]._visible = true; equates to this.Hellraiser._visible=true;
- enjine0
use eval();
people don't like it because i think it does some buggy stuff, but it works perfectly for what you need. i do that it like this all the time:function dowhatever(mc){
mc._x += 100;
}
dowhatever(eval(target_mc));
- fate0
Well i haven't had anything that works yet in this thread. Unfit's solution would just make it global but there are still problems referencing it. The eval solution is some messed up bit of syntax.
- enjine0
no, the eval syntax is correct.
give it a try... that's how functions are properly declared and called in basic procedural programming.
- aaakpth0
the "this" code given has worked for me over and over.
way to thank people for trying to help.
- fate0
aakpth, the "this" code, even if it was written correctly, even if it did work, works only for nested clips. That is not what I need.
- connerd0
var mc = this['myMovie'];
mc.goToAndPlay(1);would also work.
your problem is most likely the 'this' issue. it tends to fuck up when used inside functions. i usually use something like this:
thisRef = this;
function playClip(mc) {
thisRef.mc.gotoAndPlay('etc');
}playClip('myMovieClip');
in this case you don't need the square brackets or the eval statement. you only really need them when you're using variables in the name of your stage objects.
(ie:
mov = thisRef['mov_' + i]; )hope that helps a little
- fate0
I declared the variable and tried to use it these ways.
var=kitty
_root.var.somethiing();
_root.[var].something();I haven't tried the
var=this['kitty']
yet, don't have access to flash at the moment.
- enjine0
_root.[var].somethin g();
^ that line is probably your problem. it should be:
_root[var].something();
(there shouldn't be a period before the brackets)
- fate0
ah thanks enjine, I'll try that when I get home.
- System-Idle0
was just about to post the same thing
_root[var].somethin g();
- arlo0
You can also path it as far along as you need and then use brackets, like
_root.player.controls[varname...Or use complicated vars like
_root.display[_root.position.top...
- unfittoprint0
the reason I used global was because of a recent project where I wanted to use a soundObject on the _root without creating a new one for each loaded swf.
So, by creatin a prototyp using _global variable, every loaded swf would target correctly the object without creating a target var in each one.i've got an headache.
- fate0
that's alright unfit, I appreciate yours and karlj's and everyone else's help. I'm just bitter while at Academia.