dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Loadvars() issue

  1. #1
    Friendly fire ain't. skd's Avatar
    Join Date
    Mar 2002
    Location
    toronto.ca
    Posts
    389
    I need to fully load variables with LoadVars on a button release, so I put this code in:
    Code:
    on (release) {
    stuff = new LoadVars();
    stuff.load("vars.txt");
    while (stuff.loaded == false) {
    }
    }
    Basically, I figure that my action will loop until the variables are loaded, but what happens is the code goes in a dead loop. Any suggestions for alternatives?

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    this is not a while loop, looks more like an if statement. A while loop looks something :

    i=1;
    while(i<=10){
    load something;
    i++;
    }

  3. #3
    Senior Member
    Join Date
    Sep 2001
    Posts
    178
    Hi,
    First, add this to the end of the var.txt file:
    "&done=1"
    Then try this:

    Code:
    on(release) {
        i = 0;
        stuff = new LoadVars();
        stuff.load("vars.txt");
        while(i=0) {
            // Commands Go Here
            if (stuff.done) {i=1;}
        }
    }
    Hope this helps. Chuckles8421

  4. #4
    Senior Member
    Join Date
    Nov 2000
    Posts
    142
    actually it should be while(i==0), otherwise you are just assigning the value 0.
    his original code does and should work, loaded is a property of the LoadVars object, i'd reccommend passing the while loop onto a frame instead of leaving it on the button, you could be running into probs becuase of it looping during a state. i've found it easier to use the loaded property vs using the old ok=1 method, keeps on less unneccessary variable out of your movie.

    while loops can be sentinel based => while(i<=100)
    as well as boolean => while(myVarObject.loaded) {this would be while the value is true}

  5. #5
    Senior Member
    Join Date
    Jul 2000
    Posts
    336
    You should be able to do this --

    on (release) {
    stuff = new LoadVars();
    stuff.onLoad = function() {
    whatever code you want it to do once loaded;
    }
    stuff.load("vars.txt");
    stop();


    --

    what i'll do a lot of times is put that stop() action in there on the frame that is loading the data, then put a
    play() action in the onLoad function, so the movie will stop, then continue playing once the load is finished..

    hope that helps..

    .fe.

  6. #6
    Friendly fire ain't. skd's Avatar
    Join Date
    Mar 2002
    Location
    toronto.ca
    Posts
    389
    The last variant surely makes sense. I'll check it out.

    What I was thinking is that as the vars in the object are loaded, the 'loaded' property becomes true. Thus my while loop would loop until stuff loads. I tried to somewhat avoid cluttered code, but heh...


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