Posts Tagged ‘inspectable’

I had to piece this info together from bits and bobs all over the net, and even some experimentation.  I searched a LOT and there wasn’t one page that dealt with it in its entirety.  And I still had to work out some of this through trial and error.

These instructions assume you already know how to construct a class file and link it to your MovieClip.

Above your member variable that you want to expose, simply put [Inspectable], and don’t give a starting value, eg.

[Inspectable]
private var start_x:Number;

Every time you make changes like this, you have to

  1. Right click the movieclip in the library, click “Component Definition” remove all parameters (with minus button) delete the Class name, and click OK
  2. Go back to Component Definition again and re-enter the Class name (name of your linked class) and click OK
  3. Delete the MovieClip instance from the stage
  4. Re-add the MovieClip to the stage, and give it it’s instance name again.
  5. Click on the instance and on the Properties pane, under Component Parameters, you should see the variables – enter a starting value for the variable.  (A default parameter will not work, you need to enter one here to kick it off)

Additionally, if you need access to this variable to initialise the object, it won’t be available when the Class constructor is run, it’s only available when the first frame is run.  You have to add a little init hack, by creating a one time event for EnterFrame to an init function which removes itself from the event handler.  Eg.

import flash.events.Event;
[Inspectable]
private var my_var:String;

public function MyClass()
{
    addEventListener(Event.ENTER_FRAME, initHandler);
    trace("my_var has no value:"+my_var);
}

private function initHandler(evt:Event):void
{
    removeEventListener(evt.type, initHandler);
    trace("my_var now has a value:"+my_var);
}
Advertisements