This workflow is more or less what the Flex components follow:

package {

import flash.display.MovieClip;

public class Rectangle extends MovieClip {
private var _prop:String = "Hello";
 private var propChanged:Boolean = false;
public function Rectangle():void {
  trace("Rectangle ::: CONSTRUCTOR");
private function init():void {
  trace("Rectangle ::: init");
  // do stuff here
protected function commitProperties():void {
  trace("Rectangle ::: commitProperties");
  if(propChanged) {
   trace("    - propChanged: ", propChanged);
   trace("    - prop: ", _prop);
   propChanged = false;
   // do stuff with _prop
 public function get prop():String {
  trace("Rectangle ::: get prop");
  return _prop;
 public function set prop(value:String):void {
  trace("Rectangle ::: set prop");
  if(value != _prop) {
   _prop = value;
   propChanged = true;


----- Original Message ----- From: "Gregory N" <>
To: "Flash Coders List" <>
Sent: Thursday, February 19, 2009 10:25 AM
Subject: Re: [Flashcoders] component def doesn't pass params to constructor?


Haven't you read my reply to one of your prev. questions?
Well, let me quote it here again:
Subject: Re: [Flashcoders] my component not instancing properly on  timeline

It seems your problem is similar to one I had with my components.
The matter is that, unlike their behavior in AS2, in AS3 (CS3)
components setters of  [Inspectable] parameters are called lo-o-ong
AFTER constructor

As described here
So, even if I set my init() as listener for ADDED_TO_STAGE event...
it's still before setters.

for now, I found a solution:
I put my init() in ENTER_FRAME listener and then remove this listener :-)
This means that listeners are called before 1st  ENTER_FRAME event.
Perhaps my solution isn't too elegant.... but it works :-)

Also, be sure to duplicate default values for your parameters :-)

Note that the above solution is intended to use with sprite-based components.
Perhaps if you subclass UIComponent, the situation with setters is
better... perhaps :-)

Flashcoders mailing list

Reply via email to