AS3 Game Object Editor Class Markup
The game object editor will work with metadata that's been applied to variables or accessors. The only constraint is that they need to be public
.
Details
The simplest form is adding the markup to a public variable:
[Editable]
public var active:Boolean = true;
Here, the active bool is exposed for editing by simply adding the Editable
metadata before the variable. As the default for Boolean is the type checkbox (see Metadata syntax for more info on the Editable
metadata tag)
Accessors
After public variables, accessors that define a public getter and setter (i.e. defined as readwrite
) are the easiest to set up. Using the example from before, it's simply:
[Editable]
public function get active():Boolean { return this.m_active; }
public function set active( b:Boolean ):void
{
this.m_active = b;
}
Write-only
Write only accessors are created by only defining a public setter. You can use write only accessors with the game object editor; the only drawback being that as the value of the property can't be accessed, it won't be displayed properly in the editing component.
[Editable]
public function set active( b:Boolean ):void
{
this.m_active = b;
}
Read-only
You can use read only accessors with the game object editor, but by default the type is set as "watch"
meaning you can't edit it. All additional parameters are ignored.
// here, the default type of "checkbox" will be ignored and
// "watch" will be used in it's place
[Editable]
public function get active():Boolean { return this.m_active; }
Editing super variables
If you have a class that inherits from another class, but you still want to open a superclass variable up to editing, then you just have to add an Editable
metadata tag, with the "field"
specifying the variable you want to use.
Using our previous example, if our class extends from Sprite
and we want to keep track of the x
and y
values, we can add metadata thusly:
// we want to watch the "x" and "y" properties of the class
[Editable( field = "x", type="watch" )]
[Editable( field = "y", type="watch" )]
// continue as normal
[Editable]
public function get active():Boolean { return this.m_active; }
public function set active( b:Boolean ):void
{
this.m_active = b;
}
Comments
Submit a comment