saving external variables in a class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Omega
    New Member
    • Oct 2007
    • 12

    saving external variables in a class

    Hello,

    For my flash project I want to read variables from a text file and store them locally in flash variables. This workes fine if I put everything directly inside the flash project file (actions belonging to a certain frame). Because I need to write a lot of code I want to put it all inside an external actionscript file / class(es).
    When I define a variable (like 'dummy' in the example below) and copy a value read from a text file to it, it fails (that is, the 'trace' returns 'undefined').
    If I move the 'dummy = 2' line directly after 'function getInfo[..]{' it works fine. What goes wrong in the code below? And how can I fix it (that is, 'dummy' should still hold the assigned value (2) after the reading process).

    Note: I left out the actual reading actions inside the 'if(success)' part for simplicity reasons.

    Code:
    class readMatchData 
    {
       var dummy:Number;  	    
    
       // Constructor function
       function readMatchData()
       { ; }
    
       function getInfo(roundNum:Number):Void
       {
          var lv:LoadVars = new LoadVars();
          lv.onLoad = function(success:Boolean):Void 
          {
             if (success)
             {
                dummy = 2;  //this.dummy = 2; 
             } 
          }	 
          lv.load("round"+roundNum+".txt");       
          trace(dummy);
       }
    }
    Thanks in advance!
  • Omega
    New Member
    • Oct 2007
    • 12

    #2
    By the way, adding

    Code:
    else dummy = 3;
    trace(dummy);
    between line 17 and 18. Results in the following trace:

    Code:
    undefined
    2
    In other words, it appears that the second trace is executed before the first. (???).

    Comment

    Working...