A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: loadVars(); Help

  1. #1
    Junior Member
    Join Date
    Nov 2000
    Posts
    20
    Code:
    myLoadVars = new loadVars();
    myLoadVars.load("url");
    myLoadVars.onLoad = function( success ) {
         if ( success ) {
              // do something here
         } else {
              trace("load failed");
         }
    }
    By using this all my variables load into myLoadVars. I can't seem to access the variables through out my flash movie. Is there a way to load all the varibles in the main time line for easy access?

  2. #2
    Junior Member
    Join Date
    Mar 2001
    Posts
    6
    if you are running that code on the maintimeline you access variables loaded into it like:

    myLoadVars.variable

    if you were on a timeline of an MC on the main timelien you use:

    _root.myLoadVars.variable

    or

    _parent.myLoadVars.variable

    however a new and interesting feature of MX is the _global command.

    if you use:

    _global.myLoadVars = new loadVars();
    myLoadVars.load("url");
    myLoadVars.onLoad = function( success ) {
    if ( success ) {
    // do something here
    } else {
    trace("load failed");
    }
    }

    you can then access the variables in your loadvars from anywhere using myLoadVars.variable

    cool ah

    hope this helps

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    105
    That's pretty cool.

    I'm loading a text file using your code just above.
    Is there a way to either transfer all the variables to the _root. instead of myLoadVars or can I do the same thing another way in order to get it to load into the _root?

    I know I can just use the loadMovie script and it will automatically load into _level0, but I need a way to check whether or not the txt file has been loaded using actionscript and this seems like a good solution.

    Any ideas?

  4. #4
    Senior Member
    Join Date
    Jul 2000
    Posts
    419

    here you go!

    add the first function below once on the first frame of movie, now all of your loadVars objects will have a new function called "copyVars", pass it a movie target, and it will copy all the vars inside the loadVars object into that movie;


    Code:
    LoadVars.prototype.copyVars = function(target){
    	for(var i in this){
    		if(typeof(this[ i ]) != "function"){
    			target[ i ] = this[ i ];
    		}	
    	}
    }
    
    
    myLoadVars = new loadVars();
    myLoadVars.load("url");
    myLoadVars.onLoad = function( success ) {
         if ( success ) {
              // copy vars to root
    		  myLoadVars.copyVars(_root);
         } else {
              trace("load failed");
         }
    }

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Posts
    105
    zaxis,

    You're a Rock Star!

    You saved me a lot of grief.

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