Undefined variables just after loadVariablesNum()

  • mankytongue
  • Born
  • Born
  • mankytongue
  • Posts: 4

Post 3+ Months Ago

hi, I don't seem to be able to understand why the following code outputs "undefined" when I test run it, I mean, usually the variables are loaded aren't they?


Code: [ Select ]
if (_global.theLanguage==undefined){
    _global.theLanguage = "en.txt";
};

loadVariablesNum(_global.theLanguage, 0);
if (_global.currentPage==undefined){
    _global.currentPage = mainurl
};
trace (mainurl);
trace (_global.currentPage);
  1. if (_global.theLanguage==undefined){
  2.     _global.theLanguage = "en.txt";
  3. };
  4. loadVariablesNum(_global.theLanguage, 0);
  5. if (_global.currentPage==undefined){
  6.     _global.currentPage = mainurl
  7. };
  8. trace (mainurl);
  9. trace (_global.currentPage);


the file "en.txt" contains a list of variables which I know get loaded because some variables are used as data for some dynamic text fields and they change to reflect the variables, but how come when I trace mainurl I get "undefined" ?

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

As it is now the movie gets no time to load the vars completely before the if(_global.currentPage==undefined) fires.
Even if it did have time you would shortly after notice that the path to mainurl is wrong if this was in an on(press) or somthing :wink:

This involves creating an object to hold all of the variables that are in that text file & only doing somthing with them when the onLoad event triggers it.

Any variable loaded can be accessed through _global.languageVars.variableName of course replacing .variableName with whats in the file.
Code: [ Select ]
on(press){
    if (_global.theLanguage==undefined){
        _global.theLanguage = "en.txt";
    };
_global.languageVars = new LoadVars();
_global.languageVars.onLoad = function(success){
    if(success){
        if (_global.currentPage==undefined){
            _global.currentPage = this.mainurl; /*since theese actions are inside an event for an object, we can access properties/variables of this object with "this" (this._alpha, this.variableName, ect..)*/
            trace (this.mainurl);
            trace (_global.currentPage);
        }
    }else{
        trace("failure");
    }
}
_global.languageVars.load(_global.theLanguage);
}
  1. on(press){
  2.     if (_global.theLanguage==undefined){
  3.         _global.theLanguage = "en.txt";
  4.     };
  5. _global.languageVars = new LoadVars();
  6. _global.languageVars.onLoad = function(success){
  7.     if(success){
  8.         if (_global.currentPage==undefined){
  9.             _global.currentPage = this.mainurl; /*since theese actions are inside an event for an object, we can access properties/variables of this object with "this" (this._alpha, this.variableName, ect..)*/
  10.             trace (this.mainurl);
  11.             trace (_global.currentPage);
  12.         }
  13.     }else{
  14.         trace("failure");
  15.     }
  16. }
  17. _global.languageVars.load(_global.theLanguage);
  18. }


To explain why th epath would have been wrong before,
If that was inside an on(press) ect... it was loading variables into _level0 if accessed with _level0.mainurl then it would work .... provided the variables have been fully loaded first :wink:
  • mankytongue
  • Born
  • Born
  • mankytongue
  • Posts: 4

Post 3+ Months Ago

Thanks a lot for your help :)

this script isn't in an on (press), it's a script that runs in the first frame of the scene, so I deleted the on(press){ and it's closing } and tried running it, but I get the following error

Code: [ Select ]
**Error** Scene = main, Layer = Background, image = 1 :Line 2 : Syntaxe Error.
      if (_global.theLanguage==undefined){
  1. **Error** Scene = main, Layer = Background, image = 1 :Line 2 : Syntaxe Error.
  2.       if (_global.theLanguage==undefined){


which is strange because it's exactly the same code as in my original script which doesn't have errors...

Thanks again :wink:

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 19 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.