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.
Expand|Select|Wrap|Line Numbers
- 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);
- }
- }