Search code examples
flashactionscript-3parametersflashvars

Problems with accessing FlashVars via parameters in AS3


I keep getting compiler errors when I try to access flashVars in an AS3 class.

Here's a stripped version of the code:

package myPackage {
 import flash.display.Loader;
 import flash.display.LoaderInfo;
 import flash.display.Sprite;
  public class myClass {
    public function CTrafficHandler() {
        var myVar:String = LoaderInfo(this.root.loaderInfo).parameters.myFvar;}}}

And I get a compilation error:

1119: Access of possibly undefined property root through a reference with static type source:myClass.

When I change the class row to

public class myClass extends Sprite {

I don't get a compiler error, but I do get this in the output window:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Via the debugger (as suggested) I can see that this.root is null.

How can I solve this problem?


Solution

  • I found what the problem was. The class in question wasn't the main class used in the project, but rather a secondary class.

    I've moved the code to the main class to get the parameters and after I got them, I sent them to the class constructor function.