dcsimg
A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Using arrays in a ASCII (text) file being included by ActionScript

  1. #1

    Exclamation

    Ok, first of all I'd like to introduce myself really quick. I've been looking around and think this is a great site for some time now, finally registered because I had a question that has stumped me. I just started learning ActionScript a couple days ago and have made some great progress (it's easy for me to pick up as I've been doing PHP for some time now and the syntax is quite similar in some parts.)

    Now, on to my question:

    I'm loading variables from an ASCII file in the same directory (on a computer, this is an .exe application.) Now the file loads fine, but what I'm trying to do is use arrays in the text file. Here's the context of my text file:
    Code:
    &servers=1
    &server[1]=http://www.agigagames.com/YaPP/
    &servername[1]=Testing server
    &loading=NO
    My code for loading the file:
    Code:
    loading = "YES";
    loadVariablesNum("servers.yafc", 0);
    The problem is in the next bit of code, I can't get it to add the item to the listbox. It adds an item, but all that's there is a , yet I've tried putting in a dynamic text box with the var of servername[1] and it displayed fine.
    Code:
    n = 1;
    while (n <= servers) {
    	serverslist.addItem(servername[n],server[n]);
    	n++
    }
    stop();
    I appreciate any responses, thanks!

  2. #2
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    Yeah, you can't store arrays in a text file. In yours, it reads the variable as server[1], it doesn't regard it as part of an array. You have to try doing it like this

    server=myserver1|myserver2|myserver3

    then in Flash

    myArray = server.split("|");

    then you'll have an proper array in Flash

    myArray[0] will equal myserver1
    myArray[1] will equal myserver2

    etc

    Hope this helps,

    Chi

  3. #3

    Thanks!

    Oh I see, didn't think of the | method (I'm used to using databases, not having to split up information in a text file.)

    I'll give it a shot, thanks so much!

  4. #4

    Worked, but still haveing some problems

    Ok, that worked great (thanks again! ) but I still have one minor problem. It doesn't seem to be reading the first variable from the ASCII file (which is now server_num) because unless I manually set that variable in that actionscript, it freezes on the loop. If I set it to the same thing that it's in the (or something different) it works fine, so it's not my loop. The loading functions stayed the same, but I changed the loop and text file (it was freezing before I changed it to what you said.)

    Text file:
    Code:
    &server_num=2
    &servers=http://www.agigagames.com/YaPP/|http://yapp.phpworld.net/YaFC/
    &servernames=Testing server|Second testing server
    &loading=NO
    Loop:
    Code:
    n = 0;
    fservers = servers.split("|");
    fservernames = servernames.split("|");
    while (n <= (server_num-1)) {
    	serverslist.addItem(fservernames[n],fservers[n]);
    	n++
    }
    stop();

  5. #5
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    Hmm, try it as

    server_num=2
    &servers=http://www.agigagames.com/YaPP/|http://yapp.phpworld.net/YaFC/

    take the first ampersand out

  6. #6
    Already tried that, didn't work (will try again though.)


    Trying....

    Nope, didnt work.


    Thanks for all the help,
    Jedi~

  7. #7
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    Oh, try

    while (n <= (parseInt(server_num)-1)) {


  8. #8
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    Also, with your structure as it is, you don't have a need for a counter, you can use

    while (n <= (fservers.length - 1)) {

  9. #9
    That worked, and I learned a new thing with each of those posts, thanks very much man! Now I only wish the creativity I used to have for design/animation with Flash would come back to me


    Thanks a lot,
    Jedi~
    [Edited by Rogue Jedi~ on 07-05-2002 at 04:19 PM]

  10. #10

    One more

    Ok, I have one more question, this time about the change event on the list box.

    I have it set to this function, but the dynamic text box selServerName won't seem to change.

    Code:
    function changeServer() {
    	server = serverslist.getSelectedItem().data;
    	_global.selServerName = serverslist.getSelectedItem().label;
    	checker = server.substr(-3);
    	if (checker != ".php") {
    		_global.server = server + "YaFC.php";
    	}
    }
    Any ideas?

  11. #11
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    If selServerName is a text box, you need to go _global.selServerName.text = serverslist.getSelectedItem().label;
    if it's the variable of the text box it should be ok...

  12. #12
    It's the var associated with the text box, but I'll try using the instance name and your method instead.


    Trys...

    Didn't work either :-\

  13. #13
    After doing a couple tests I think I determined the cause of the problem, but I don't know how to fix it.

    I determined that the function was indeed being run by using this in the function:
    Code:
    serverslist.addItem("test","test");
    When an item was seleted, it did indeed add the item test.

    Then I determined that the problem is that the variable isn't going out of the function (I'm pretty sure that's the problem anyways, I tried using this in the function and it didn't change:
    Code:
    _global.selServerName = "test";

  14. #14
    Senior Member chi-styler's Avatar
    Join Date
    Jul 2001
    Location
    Bristol, UK
    Posts
    1,237
    I think it's the global thats causing the problem. If you reference the variable or text box using _root or _parents it'll probably work. I'm not quite sure what the deal is with _global, I've never had to use it, whether it involves some declarations or something I don't know..

  15. #15
    Root did the trick, I saw the _global in the reference, read a bit, and realized it was similar to the global function in PHP except for the fact that it doesn't work

    Ok, so my next question is... just kidding, I'll ask later


    Can't thank you enough man!

    Jedi~

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