PDA

View Full Version : How to increast array value?


Dracil
02-10-2010, 04:41 PM
Ok i have an array myArray[0]

Now how do i increase the value by +1 ? is it something like myArray[i++] ?

I want to have an if statement like
If(myArray[i] = "1")
{
gotoAndPlay(1)
}
else if (myArray[i] = "2")
{
gotoAndPlay(2)

}

This will be put into a frame action, and it will be read serveral times, so myArray[0],myArray[1],myArray[2],myArray[3],myArray[4] etc etc will be read, so how do it set it to increase by + 1 ?

is it something like myArray[i] = myArray[i++]; ?

Noct
02-10-2010, 05:08 PM
Well, you could inc the number in an array slot by jus doing this:

myArray[0]++;
But, your if statement is showing you trying to evaluate it against a string ("1"), which would have to be parsed to a number before you could inc it.

Also, you wouldn't even need an evaluation to continue the trend you're showing there, you could use the number in the array itself to send the timeline to the proper frame:

gotoAndPlay(parseInt(myArray[i]));

Dracil
02-10-2010, 10:35 PM
This is driving me crazy, i get an array with this code:



var LV:LoadVars = new LoadVars();
LV.onLoad = function(ok){
if(ok){
var myArray:Array = this.Response.split("|");
for(i=0; i<myArray.length; i++){
trace(myArray[i]);


if(myArray[0] == "1")
{
gotoAndPlay(24);
trace("");
}
if(myArray[1] == "2")
{
gotoAndPlay(24);
trace("");
}



}
}else{
gotoAndPlay(2);
}
}
LV.load("my adress ");



And it works GREAT on that very scene, but when i go to my other scenes i try to use myArray[0] and it wont work? why does my array only work on one scene and not in whole movie ?

Noct
02-11-2010, 02:33 PM
Try moving the array declaration outside of the load method.

var myArray:Array;
var LV:LoadVars = new LoadVars();
LV.onLoad = function(ok){
if(ok){
myArray = this.Response.split("|");
//....