Muzak,

Nice addition, thanks for pointing to it.
Frankly, I'd prefer to avoid calling commitProperties() after *each*
of the setters...
Anyway, this way looks better than my enter_frame trick :-)

However, the problem " none of the setters are called if no
inspectable params were changed" still remains. So we have to
duplicate default values in [Inspectable] and constructor/declaration
(or some init function)

On 2/19/09, Muzak <p.ginnebe...@telenet.be> wrote:
> 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");
>    init();
>   }
>
>   private function init():void {
>    trace("Rectangle ::: init");
>    // do stuff here
>    commitProperties();
>   }
>
>   protected function commitProperties():void {
>    trace("Rectangle ::: commitProperties");
>    if(propChanged) {
>     trace("    - propChanged: ", propChanged);
>     trace("    - prop: ", _prop);
>     propChanged = false;
>     // do stuff with _prop
>    }
>   }
>
>   [Inspectable(defaultValue="Hello")]
>   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;
>     commitProperties();
>    }
>   }
>  }
> }
>
> regards,
> Muzak
>
> ----- Original Message -----
> From: "Gregory N" <greg.gousa...@gmail.com>
> To: "Flash Coders List" <flashcoders@chattyfig.figleaf.com>
> Sent: Thursday, February 19, 2009 10:25 AM
> Subject: Re: [Flashcoders] component def doesn't pass params to constructor?
>
>
>> Michael,
>>
>> 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
>> http://www.bit-101.com/blog/?p=1181
>> 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
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>


-- 
-- 
Best regards,
 GregoryN
================================
http://GOusable.com
Flash components development.
Usability services.
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to