-
Arrays in .txt ?
Can i have my Arrays done in a .txt and then load them into flash?
I would like to have this: idMovie =["mov1", "mov2", "mov3"];
Instead of idMovie1 = mov1 &idMovie2 = mov2 &idMovie3 = mov3
-
put in your text file a string seperated by ","
myString="1,2,3,4,5,6,7"
and us split to output to array
See example code below.
myString="1,2,3,4,5,6,7"
myArray=myString.split( ",")
trace(myArray)
-
Hey that's what i wanted to do! it works pretty well, thankyou
-
Argh!!!
Now i want to call a random value from the array and it always return 0 and some times 1 or 3 but most of the time it returns 0.
on (press) {
trace(random(myArray.pop()));
}
that's what im doing the array.pop() Removes the last element of an array and returns it's value. i want to do it randomly not the last nor the first, if anyone knows please help me out!
-
pop only returns the last avlue in an array.
see the following code on how to get a random index
(this doesnt delete the value just returns)
myString="1,2,3,4,5,6,7"
myArray=myString.split( ",")
trace(myArray)
//gives a random value between the number of Indexs in array (-1 to reset to 0 initial index)
randomIndex=Math.floor((myArray.length-1)*(Math.random())+0.5);
//get value from this index
myRandomValue=myArray[randomIndex]
trace(myRandomValue)
hope that helps
-
I was too far away from getting it work! Thankyou man it works perfectly. You save me weeks of head cracking hehehe. Thanks a lot!!!
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
|