actionscript-3flashparametersflash-cc

Inspectable parameters in Flash CC do not acquire value


When moving to Flash CC, the following problem occurred in my flash project.

Consider this class definition:

public class Test extends MovieClip {
  [Inspectable(type="String", defaultValue="val")]
  public var param :String;

  public function Test() {
     trace(param);
  }
}   

I have a symbol "Symbol 1" which (via the Library panels Properties) is linked to the class Test and (via the Component Definition) is also set to the class Test, and this dialog box displays the parameter "param" with value "val". I have an instance of Symbol 1 on the Scene. The parameter "param" appears in the properties of this instance, with the value "val", as expected.

The only problem is that during runtime, the value of the parameter "param" is equal to null, as confirmed during the execution of the classes constructor, which outputs "null".

Does anyone know why this is happening?


Solution

  • The Inspectable tag is needed by Flash to populate the component properties panel in order to set values manually. These parameters, both default and user input, are not available at instantiation, but they are available only at the following frame. In order to have default values at instantiation you must set the default value also on the variable itself.

      [Inspectable(type="String", defaultValue="val")]
      public var param :String = "val";
    

    Also, before you go crazy accessing values inserted with property inspector, remember to add an enter frame event before accessing those values.

    What I usually do in my components: 1 - Populate default in both inspectable and variable 2 - On instantiation, if a parameters object is received, then I know it's instantiated in code and values are inside the parameters object 3 - If a parameters object is not received, then instantiation is done on timeline visually, therefore I access properties on next frame