Skip to content

Inspectable Metadata

Robert Silverton edited this page Aug 30, 2013 · 16 revisions

Overview

You may have noticed this sort of metadata in CadetEngine code above various public properties of classes:

[Inspectable( label="Line alpha", priority="100", editor="Slider", min="0", max="1" )]
public function set lineAlpha( value:Number ):void

The purpose of this code is to expose these properties as 'inspectable' to CadetEditor. This means that when the object is selected in CadetEditor in the EditorView or OutlinePanel, the inspectable properties of the object will appear with value editors in the PropertyInspector.

The PropertyInspector has a number of default editors, these are:

  • ColorPicker
  • CheckBox
  • DropDownMenu
  • NumberInput
  • NumericStepper
  • Slider
  • TextInput

If you simply specify that a property is inspectable by adding the [Inspectable] metadata above it and don't pass any other parameters, a simple type check on the property is performed and a default property editor is selected for you. For example:

[Inspectable]
public function set lineThickness( value:Number ):void

A NumberInput would appear in the PropertyInspector for the "lineThickness" property above, or for any property which is a Number and didn't specify another type of editor in the [Inspectable] metadata.

[Inspectable]
public function set loop( value:Boolean ):void

A CheckBox editor appears for any Boolean values that don't specify another type of editor.

[Inspectable]
public function set bitmapData( value:BitmapData ):void

If the property is neither a Number or a Boolean, the PropertyInspector assumes it's a String. For the example above, you would see a TextInput field next to the "bitmapData" name, and clicking it would get you a run time error when it fails to convert your String to a BitmapData, so make sure to set the "editor" property in the metadata if your property is not a simple type!

Specifying An Editor Type

cadet2D.components.skins.GeometrySkin

[Inspectable( editor="Slider" )]
public function set fillAlpha( value:Number ):void

cadet2D.components.skins.GeometrySkin

[Inspectable( editor="ResourceItemEditor")]
public function set fillBitmap( value:BitmapData ):void

cadet2D.components.textures.TextureAtlasComponent

[Inspectable(editor="ResourceItemEditor", extensions="[xml]")]
public function set xml( value:XML ):void

cadet2D.components.particles.PDParticleSystemComponent

[Inspectable( editor="ResourceItemEditor", extensions="[pex]")]
public function set xml( value:XML ):void

cadet.components.sounds.SoundComponent

[Inspectable(editor="ResourceItemEditor", extensions="[mp3]")]
public function set asset( value:Sound ):void

cadet2D.components.skins.GeometrySkin

[Inspectable( editor="ComponentList", scope="scene" )]
public function set lineTexture( value:TextureComponent ):void

ComponentList scope = "scene" or "parent"

Additional Properties

The following properties are also recognised by the PropertyInspector:

priority

[Inspectable( priority="58" )]

Priority is used to allow control over the order of the appearance of value editors in the PropertyInspector. Properties with lower priorities will appear nearer the top of the PropertyInspector panel.

label

[Inspectable( label="Fill bitmap")]

The default behaviour for a name field of a value editor in the PropertyInspector is to use introspection to set the name field value to be same as the name of the property, i.e. the name "fillBitmap" will appear for the "fillBitmap" property. If however you would like the name to be "Fill bitmap" instead, you can set the label metadata for the property to reflect this.

Editor Specific Additional Properties

Other than the above, any additional properties in the metadata are related to the public properties of the editor being used. The following values can be set on the editors listed below, in order to allow more fine-grain control.

DropDownMenu

[Inspectable( editor="DropDownMenu", dataProvider="[Gravity,Radial]" )]
public function get emitterType():String 

dataProvider:ArrayCollection

NumberInput

[Inspectable( editor="NumberInput", min="0", max="360", numDecimalPlaces="0" )]
public function set rotation( value:Number ):void

min:Number, max:Number, numDecimalPlaces:uint

NumericStepper

[Inspectable( editor="NumericStepper", min="1", max="10", numDecimalPlaces="0" ) ]
public var numVelocityIterations:int = 2;

min:Number, max:Number, numDecimalPlaces:uint, stepSize:Number

Slider

[Inspectable( editor="Slider", min="0", max="1", snapInterval="0.1" )]
public function set fillAlpha( value:Number ):void

min:Number, max:Number, snapInterval:Number