Valuable parameters in Flash CC are not getting value

When upgrading to Flash CC, my Flash project encountered the following problem.

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 Properties of the Library Panel) is linked to the Test class and (via the component definition) is also set to the Test class, and this dialog displays the "param" parameter, with the value "val". I have an instance of Character 1 in the Stage. The "param" parameter appears in the properties of this instance with the value "val", as expected.

The only problem is that the "param" parameter is null at run time, which is confirmed when the class constructor runs, which outputs "null".

Does anyone know why this is happening?

+3


source to share


1 answer


The Inspectable tag is required by Flash to populate the component's properties panel to manually set values. These options, both by default and to the user, are not available on instantiation, but they are only available in the next frame. To have default values โ€‹โ€‹when instantiated, you must set a default value for the variable itself as well.

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

      



Also, before you get crazy about accessing the values โ€‹โ€‹inserted into the Property inspector, be sure to add an input frame event before accessing those values.

What I usually do in my components: 1 - Populating the default value for both checked and variables 2 - On instantiation, if the parameters object is received, then I know it was created in code and the values โ€‹โ€‹are inside the parameters object 3 - If no parameters object is received then rendering is done on the timeline visually, so I get access to the properties of the next frame

+3


source







All Articles