A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Arrays in .txt ?

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    102

    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
    -=Gingko=-

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    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)

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    102
    Hey that's what i wanted to do! it works pretty well, thankyou
    -=Gingko=-

  4. #4
    Senior Member
    Join Date
    Jan 2001
    Posts
    102

    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!
    -=Gingko=-

  5. #5
    Senior Member
    Join Date
    Apr 2001
    Location
    UK
    Posts
    493
    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

  6. #6
    Senior Member
    Join Date
    Jan 2001
    Posts
    102
    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!!!
    -=Gingko=-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center