Referring to a variable

say i have this code:

blah = “123 + i”

so blah is a variable right? so how would i refer to this variable?
i want to be able to do:

_root.blah.onPress = function ()

but this won’t work beause you need an instance name instead, so how would you do this? thx, i hope you understood what i was saying :slight_smile:

  1. dont start names with numbers
  2. How do I adress instances by variables ?

i understand some of that now, but when i try it, it seems to not work? can you check whats wrong with this code plz? I keep getting an output error, and i’ve been staring at the code for a good amount of time, but still not notice whats wrong :-/

Here it is:
[AS]
for(i=0, i<10, i++) {
dupename = _root[“newbox”+i]
duplicateMovieClip(_root.box, dupename, 1)

}
_root[“newbox”+i].onPress = function() {
startDrag(this, true)
}
[/AS]

thx

try this:

for (i=0, i<10, i++) {
dupename = "newbox"+i;
duplicateMovieClip(_root.box, dupename, i)
_root[dupename].onPress = function() {
        this.startDrag();
};
}

:wink:

I still seem to be getting an error?

Scene=Scene 1, Layer=AS, Frame=1: Line 2: ‘;’ expected
dupename = “newbox”+i;

Scene=Scene 1, Layer=AS, Frame=1: Line 7: Unexpected ‘}’ encountered

thats whats been happening with my previous code too…
Its getting really frustrating, hope someone will find out whats wrong :confused:

oh!! i didn’t notice that you have commas instead of semicolons. :stuck_out_tongue:
i shouldn’t have copied and pasted the script. :-\

for (i=0; i<10; i++) {
        dupe = duplicateMovieClip(_root.box, "newbox"+i, i);
        dupe.onPress = function() {
                this.startDrag();
        };
}

Alright this is beginning to get really annoying :-\

It again doesn’t seem to work? This isnt’ for me, but I need lots of help myself too :slight_smile: Heres the file, you think you can have a little look at it for me? thx

Oh yea, what was wrong with my code earlier? What did you mean by semicolons and commas!?

sorry… i don’t know why it didn’t work. :-\

for (i=0; i<10; i++) {
	dupe = "newbox"+i;
	duplicateMovieClip(_root.box, dupe, i);
	_root[dupe].onPress = function() {
		this.startDrag();
	};
}

fixed. =)

Originally posted by blah-de-blah
Oh yea, what was wrong with my code earlier? What did you mean by semicolons and commas!?

for (i=0, i<10, i++) comma ,
for (i=0; i<10; i++) semicolon ;

see the difference? :wink:

ah never realized that, thx very much :slight_smile:

as always… no problem. :wink: =)