A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] var's to array problem

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Posts
    3

    resolved [RESOLVED] var's to array problem

    Please help. The problem is the string of numbers load from the file.txt and look ok. But they do not become a usable array(undefined). So mc1 does not move.

    The data in the file.txt is formatted like this -
    &myData=10,15,20,25,30,35,40,45,50,55,60,65,70

    // the code

    var inc = 0;
    var lv = new LoadVars();

    lv.onLoad = function(success)
    {
    if(success)
    {
    myData = lv.myData;
    move = new Array(myData);
    }
    }

    lv.load("file.txt");

    onEnterFrame = function()
    {
    _root.mc1._x = move[inc];
    inc += 1;
    if(inc > 10) {inc = 0};
    }

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    lv.onLoad = function(success){
    move = new Array();
    if(
    success){ 
    myData lv.myData;
    move myData.split(","); // split the loaded string by the comma delimiter
    }

    hth

  3. #3
    Junior Member
    Join Date
    Jul 2008
    Posts
    3
    Thank you(a_modified_dog) so much for you help! Your code works great! I've spent far too many hours reading the actionscript dictionary, tutorials, forum threads and experimenting with the code. I've learnt alot about loading var's and array handing. But it still escaped me. I wish I had posted here earlier. I did try split, concat, push, jump, scream, and shout! and some. But not like the way you have done it. I can now see that you have to create an new array object first, then split the var's later. Thank you!

  4. #4
    Still kisses with saliva save_larry's Avatar
    Join Date
    Jul 2002
    Location
    an empowered & informed member of society
    Posts
    183
    I'm trying to do almost exactly the same thing, but I'm still getting (undefined). When I trace the variable that's being split into the array, it returns: <p align="left"></p>

    My text file is MEname9.txt and contains:
    &MEnames=1,2,3,4

    The code I have currently for this section is:
    var photoNum = 0;


    var NameLoader = new LoadVars();


    NameLoader.onLoad = function(success){
    NameArray = new Array();
    if (success){
    MEnames = NameLoader.MEnames;
    NameArray = MEnames.split(",");
    }
    }
    NameLoader.load("MEname9.txt");
    trace(MEnames);
    NameBox.text = NameArray[photoNum];

    It's identical to what a_modified_dog posted, and I can't see any difference in what I'm doing vs. what ellis001 was trying to do as far as importing the text and putting it into an array. But the array just isn't working. Any advice?
    a pig
    in a cage
    on antibiotics

  5. #5
    Still kisses with saliva save_larry's Avatar
    Join Date
    Jul 2002
    Location
    an empowered & informed member of society
    Posts
    183
    Sorry, duplicate post.
    a pig
    in a cage
    on antibiotics

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