Solved

setting a "dynamic" array .. ?

Posted on 2002-03-07
4
181 Views
Last Modified: 2010-04-03
this code sets the array _root.clip4[5] to 1 as desired.

_root.clip4[5] = 1

i need to adapt this code to set a dynamic array (one made up from two variables (variableone and variabletwo)) to equal 1

i have tried this code;

"_root.clip" + xvariable + "[" + yvariable + "]" == 1

and many other variants but been unsuccesfull ... please please please can anyone help? many thanks
0
Comment
Question by:lexfrost
4 Comments
 
LVL 4

Expert Comment

by:heddesheimer
Comment Utility
try to compose the variable name into a string variable and use the eval() function to access the dynamic variable.

That should work

Marian
0
 
LVL 19

Expert Comment

by:webwoman
Comment Utility
Your syntax is wrong if you're trying to set a value. Use
"_root.clip" + xvariable + "[" + yvariable + "]" = 1

== is checking to see if the expression is equal to 1, not setting it.

Have you tried it with no quotes?
0
 

Accepted Solution

by:
hwwong earned 75 total points
Comment Utility
you can use either of the following expression for the dynamic array:
1) eval("_root.clip" + xvariable)[yvariable]
2) _root["clip" + xvariable][yvariable]


Here is the code that you can try:

clip4 = new Array();
clip4[5] = 1;
xvariable = 4;
yvariable= 5;
//output = eval("_root.clip" + xvariable)[yvariable];
output = _root["clip" + xvariable][yvariable];
trace(output);

Henry
0
 

Author Comment

by:lexfrost
Comment Utility
eval("_root.clip" + xvariable)[yvariable]

many many thanks ..  !! as well as a lifesaving actionscript guru youre a top bloke..


thanks again,

lex
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to record live broadcast.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now