View Full Version : referring to a variable
blah-de-blah
April 17th, 2003, 08:18 AM
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 :)
senocular
April 17th, 2003, 08:21 AM
1) dont start names with numbers
2) How do I adress instances by variables ? (http://www.kirupaforum.com/forums/showthread.php?s=&threadid=12082)
blah-de-blah
April 17th, 2003, 10:11 AM
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:
for(i=0, i<10, i++) {
dupename = _root["newbox"+i]
duplicateMovieClip(_root.box, dupename, 1)
}
_root["newbox"+i].onPress = function() {
startDrag(this, true)
}
thx
kode
April 17th, 2003, 10:21 AM
try this:
for (i=0, i<10, i++) {
dupename = "newbox"+i;
duplicateMovieClip(_root.box, dupename, i)
_root[dupename].onPress = function() {
this.startDrag();
};
}
;)
blah-de-blah
April 17th, 2003, 10:55 AM
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 :/
kode
April 17th, 2003, 11:30 AM
oh!! i didn't notice that you have commas instead of semicolons. :P
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();
};
}
blah-de-blah
April 17th, 2003, 11:37 AM
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 :) 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!?
kode
April 17th, 2003, 11:50 AM
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? ;)
blah-de-blah
April 17th, 2003, 11:54 AM
ah never realized that, thx very much :)
kode
April 17th, 2003, 11:56 AM
as always... no problem. ;) =)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.