A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [CS3/AS2] Problem importing vars from text file

  1. #1
    Still kisses with saliva save_larry's Avatar
    Join Date
    Jul 2002
    Location
    an empowered & informed member of society
    Posts
    183

    [CS3/AS2] Problem importing vars from text file

    This is a repost from ellis001's RESOLVED thread. I didn't think anyone would open the RESOLVED thread.


    I'm trying to do almost exactly the same thing as ellis001, 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

  2. #2
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    PHP Code:
    var NameLoader = new LoadVars();


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

  3. #3
    Still kisses with saliva save_larry's Avatar
    Join Date
    Jul 2002
    Location
    an empowered & informed member of society
    Posts
    183
    Wow, thanks, sstalder! That gets the array working!

    I want NameArray to show the next element everytime photoNum advances (I set photoNum to 0 in this frame and have it advance in another movie clip). I guess that's my next hurdle in getting this to work. Thanks again!
    a pig
    in a cage
    on antibiotics

  4. #4
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Sounds good. If you will notice that you have to run everything inside that load function, or once the text file is loaded into memory (which is why I only moved your code into the onLoad function to get it working).

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