-
Help with Array and instance name
Hey Guys
Actionscript 2
I have a conundrum and I am stuck.
this is the problem.........
I have three sets of mc's.
the instance names are as follows;
set one is - button_1, button_2, button_3, button_4
set two is - image_1, image_2, image_3, image_4
set three is - sound_1, sound_2, sound_3, sound_4
I then have an array;
var myArray:Array = [1, 2 ,3, 4];
I then have code to randomise this array;
Array = [2 ,1 ,4 ,3 ];
now here is the problem
lets say the first number in my array is 4 I want button_4, image_4 and sound_4 to move to a specific place on the stage.
so in short I want myArray number 1 to refer to all three instances with number 1 in the name.
is there a way of having move than on mc in one position of an array?
any help would be much appreciated,
Thanks for reading this,
Neil
-
as an addition to this post
lets say if i had an array like this;
var questArray:Array = [dave_mc, jon_mc, tom_mc];
could you merge more mcs in the array like this
var questArray:Array = [dave_mc/dave_bt, jon_mc/jon_bt, tom_mc/tom_bt];
so that dave_mc and dave_bt were the same position in the array?
-
Senior Member
All you need to do is dynamically create the name. Like this:
Actionscript Code:
_root["button_"+myArray[0]]._x = 100.0; _root["image_"+myArray[0]]._x = 100.0; _root["sound_"+myArray[0]]._x = 100.0;
-
Prid - Outing
@hts5000: Haha XD Just saw yours after posting mine, and it's really similar, lol :P
--------
Let's say you have a button, instance name of my_btn, then when you wanted to reposition those 3 movieclips, use this:
Actionscript Code:
my_btn.onRelease = function(){ _root["button_"+myArray[0]]._x = 200; _root["image_"+myArray[0]]._x = 200; _root["sound_"+myArray[0]]._x = 200; }
To refer to a specific movieclip, variable, or whatever it may be, you can join pieces to locate for that specific movieclip/variable, by using: scope[text_to_join_here]
scope = _root, _parent, this
usage: _root[content to join in here]
Remember tha there is no dot between the scope and the text to join!
So, let's say we have a variable named, my_var1, we can refer to it by something like this:
Actionscript Code:
my_var1 = "you joined the text :D";
var1 = "my"; num = 1;
trace(_root[var1+"_var"+num]);
Just try it and see for yourself
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
That worked perfectly, you are the man. I can now stop headbutting my desk. Much appreciated. N
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|