View comments | RSS feed

About the Inspectable tag

You use the Inspectable tag to specify the user-editable (inspectable) parameters that appear in the Component inspector and Property inspector. This lets you maintain the inspectable properties and the underlying ActionScript code in the same place. To see the component properties, drag an instance of the component onto the Stage and select the Parameters tab of the Component inspector.

Collection parameters are also inspectable. For more information, see About the Collection tag.

The following figure shows the Parameters tab of the Component inspector for the DateChooser component:


The DataChooser component in the Component inspector

Alternatively, you can view a subset of the component properties on the Property inspector Parameters tab.

When determining which parameters to reveal in the authoring environment, Flash uses the Inspectable tag. The syntax for this tag is as follows:

[Inspectable(value_type=value[,attribute=value,...])]
property_declaration name:type; 

The following example defines the enabled parameter as inspectable:

[Inspectable(defaultValue=true, verbose=1, category="Other")]
var enabled:Boolean;

The Inspectable tag also supports loosely typed attributes like this:

[Inspectable("danger", 1, true, maybe)] 

The metadata statement must immediately precede the property's variable declaration in order to be bound to that property.

The following table describes the attributes of the Inspectable tag:

Attribute

Type

Description

defaultValue

String or Number

(Optional) A default value for the inspectable property.

enumeration

String

(Optional) Specifies a comma-delimited list of legal values for the property.

listOffset

Number

(Optional) Added for backward compatibility with Flash MX components. Used as the default index into a List value.

name

String

(Optional) A display name for the property. For example, Font Width. If not specified, use the property's name, such as _fontWidth.

type

String

(Optional) A type specifier. If omitted, use the property's type. The following values are acceptable:

  • Array
  • Boolean
  • Color
  • Font Name
  • List
  • Number
  • Object
  • String

variable

String

(Optional) Added for backward compatibility with Flash MX components. Specifies the variable that this parameter is bound to.

verbose

Number

(Optional) An inspectable property that has the verbose attribute set to 1 does not appear in the Property inspector but does appear in the Component inspector. This is typically used for properties that are not modified frequently.

None of these attributes are required; you can use Inspectable as the metadata tag.

All properties of the superclass that are marked Inspectable are automatically inspectable in the current class. Use the InspectableList tag if you want to hide some of these properties for the current class.


Flash CS3


Comments


Chris Ivey said on Jun 6, 2007 at 10:51 PM :
Documentation of the Flash 8 components showed the [inspectable] metadata used with private variables and getters/setters. The variable was declared first, then the metadata, then the getters and setters. This doesn't seem to work at all with Flash 9, which only seems to like public vars without getters and setters. This could cause BIG problems with a platform conversion I'm working on. Is there a workaround or more documentation on this issue?
gustera said on Jul 11, 2007 at 8:01 AM :
You should mention here for the users that after an auto format of the code the Inspectable tag doesn't work. In Flash MX2004 this was not a problem because auto format didn't put a semi colon at the end of the Inspectable line, but in CS3 it adds a semi colon.

Really annoing bug, which costed me tons of wasted time. :(
juankpro said on Aug 25, 2007 at 6:26 AM :
When Flash initializes Array inspectable properties, Flash does this:

arrProp = new Array();
arrProp[0] = zeroValue;
arrProp[1] = oneValue;
...

So when the getter setter gets called the first time, the Array is empty, then every call to each index will not call the setter method, only the getter.

I consider this a bad practice, and initialization should be like this:

arrProp = new Array(zeroValue, oneValue, ...);

or

arrProp = [zeroValue, oneValue, ...];

This will give a real assigned value when the component initializes.

Besides the current approach can cause some other problems like not initializing Arrays when the getter/setter uses a copy instead of the original Array.

Just consider this example:

Your getter setter methods need to make a copy of the Array and not use the original reference.
The setter method receives an Array and makes a copy with the slice or concat method and finally stores it in a property.
The getter method creates and returns a copy (created with slice or concat) of this Array property.

Using the procedure above:

1) The first line stores a copy of the empty Array.
2) In the second line and further, you get another copy (not the original Array stored in the component) and store values in it. So what you are changing is a copy instead of the original Array, letting the original Array without any elements.

This approach is used a lot by programmers to avoid users messing with the contents of critical Arrays. This is the same behavior found in Arrays properties like the filter property and like many others programmed by Macromedia/Adobe.

The question is: If they use this approach for their own objects, then why they didn't expected their users to use it.

To solve this problem probably the best way to do it is creating an initializing Boolean property initialized with to true. Detect this variable in the getter method: if it is true return the real reference to the Array, if false return just a copy. You will have to set this variable to false on the constructor or any other initializing method.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00002498.html