Hi.
My intention is to have an array with several variables, each one with a different name, all of them of the type ‘Number’. This I can do.
What I can’t do is to access the variables using the array’s index.
Let me exemplify:
Paste this on your frame 1:
trace("======at frame 1======");
//objects//
var objects:Array = new Array();
objects[0] = carroobj=1;
objects[1] = crapobj=2;
objects[2] = tractorobj=3;
objects[3] = truckobj=1;
objects[4] = hammerobj=1;
objects[5] = keyobj=1;
trace("carroobj "+carroobj);
trace("array objects "+objects);
//object frames//
var objectsframe:Array = new Array();
objectsframe[0] = carroobjframe=43;
objectsframe[1] = crapobjframe=14;
objectsframe[2] = tractorobjframe=18;
objectsframe[3] = truckobjframe=3;
objectsframe[4] = hammerobjframe=45;
objectsframe[5] = keyobjframe=70;
trace("array objectsframe "+objectsframe);
trace("carroobjframe "+carroobjframe);
Paste this on your frame 3:
stop();
trace("======at frame 3======");
for (i=0; i<objects.length; i++) {
trace("array element from objects "+objects*);
if (objects* == 1) {
objectsframe* = _root._currentframe;
trace("array element from objectsframe "+objectsframe*);
}
}
trace("array objectsframe "+objectsframe);
trace("carroobjframe "+carroobjframe);
The result will be:
======at frame 1======
carroobj 1
array objects 1,2,3,1,1,1
array objectsframe 43,14,18,3,45,70
carroobjframe 43
======at frame 3======
array element from objects 1
array element from objectsframe 3
array element from objects 2
array element from objects 3
array element from objects 1
array element from objectsframe 3
array element from objects 1
array element from objectsframe 3
array element from objects 1
array element from objectsframe 3
array objectsframe 3,14,18,3,3,3
carroobjframe 43
As you can see, the code is changing the value of the array element and not the value of the variable inside the array element.
I know my code is wrong, but how do I access and change the value of variables inside the array using the array’s index?
Thsnk you for any help.