Bug:[Inspectable] and setter property

Using  tags to mark up meta-data is a wonderful idea indeed!

In ActionScript 2, the [Instectable] tag is documented to be compatible with  both  member varibles and setter properties. But an issue I ran into recently came up to say that [Inspectble] has its flaw.

If [Inspectable]  is used with a setter property and type is set to "Object", the Component Inspecter cannot correctly pass the input data to the setter property when the movie is published. However, it works well for livepreview!

Consider the following code:

[Inspectable(defaultValue="fontFamily:Verdana,color:#000000,fontSize:12px", type="Object")]
 public function set normalStyle(styleObj:Object) {
  this.m_normalStyle = styleObj;
  this.m_rowStyleSheet.setStyle("normal", styleObj);
  invalidate();
 }

It’s all OK for livepreview, but once the movis is published, the normalStyle setter always receives am empty Object from the Component Inspecter.

I tracked down this issue and finally found that the problem lies in the way MM initializes components.

How do the values in the Component Inspecter reach the actual fields or setters of a class? Flash compiler generates OnClipEvent(construct) handler to accomplish this. The construct event is fired even before the initialize event and is designed for copying data from the Component Inspecter.

But MM’s implementation of the handler for construct event is not perfect.

onClipEvent (construct) {
/* …. */
normalStyle = {};
normalStyle["fontFamily"]="Verdana";
normalStyle["color"]="#000000";
normalStyle["fontSize"]="12px";
/* …. */
}

The [] operator will not treat a setter as a function! It even can circumvent type checking!

All will be OK if the code is written in the following syntax:

onClipEvent (construct) {
/* …. */
normalStyle = {fontFamily:"Verdana", color:"000000", fontSize:"12px"};
/* …. */
}

But MM dose not!!!

Another potential problem is that an inspectable setter will get called before the instantiation of a component. So be careful when using an inspectable setter property!

Advertisements
This entry was posted in Flash and ActionScript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s