ooops...  ui.addListener(this) ; is no necessary now in your test in my last
message;)

the

2006/11/30, eka <[EMAIL PROTECTED]>:

Hello :)

you can but a good event model use AsBroadcaster or other system to
dispatch the events :) In my personnal AS2 OpenSource framework i use a
event model compatible with W3C Dom3 event model for example (like AS3
framework).... it's more easy to use a event model to dispatch information
in callbacks methods ! If you want dispatch the information in your class...
use this.addListener(this) and you can use onX method directly on your
instance :)

class MyUIObject
 {

    /**
     * Constructor of the class.
     */
    public function MyUIObject()
    {
        this.addListener(this) ;
     }

    /**
     * Inject addListener, removeListener and broadcastMessage methods in
the prototype of the class.
     */
    static private var __INITBROADCASTER__ = AsBroadcaster.initialize(
MyUIObject.prototype ) ;

        // Public Properties

    /**
     * The code of this method is injected by the AsBroadcaster tool.
     * Use this declaration in the AS2 compilation.
     */
    public var addListener:Function ;

    /**
     * The code of this method is injected by the AsBroadcaster tool.
     * Use this declaration in the AS2 compilation.
     */
    public var broadcastMessage:Function ;

    /**
     * This method is empty but can be override by the user in this code
to notify the x value modification.
     */
     public var onX:Function ;

    /**
     * The code of this method is injected by the AsBroadcaster tool.
     * Use this declaration in the AS2 compilation.
     */
    public var removeListener:Function ;

    /**
     * (read-write) Returns the x position of the ui object.
     */
    public function get x():Number
    {
        return getX() ;
    }

    /**
     * (read-write) Sets the x position of the ui object.
     */
    public function set x( value:Number ):Void
    {
        setX( value ) ;
    }

        // Public Methods

    /**
     * Returns the x position of the UI object.
     */
   public function getX():Number
    {
       return _x;
   }

    /**
     * Sets the x position of the UI object.
     */
    public function setX( value:Number ):Void
    {
        _x = value ;
         broadcastMessage("onX" , this, _x) ;
   }

        // Private Properties

    /**
     * The internal x position of the UI object.
     */
    private var _x:Number ;

}

And in your code :

var ui:MyUIObject = new MyUIObject();
ui.onX = function ( who , x )
{
     trace("onX : " + who + " with the value : " + x) ;
}
ui.addListener(this) ;
ui.x = 25 ;

EKA+ :)

2006/11/30, Matthias Dittgen <[EMAIL PROTECTED]>:
>
> Hello EKA,
>
> thanks for your reply.
>
> to your 1: yes, i really don't wanted to use watch. the watch method
> is less performant, I have read on this list sometime before. That's,
> why I asked my question. It admit, it has been more than only one
> question. :-)
>
> to your 2: I usually give my constructor the same name as the class.
> This is a typical mistake, when I use the copy&paste&change method to
> write emails.
>
> to your 3: "is AS2 used get and set keywords to create virtual
> properties and don't use addProperty method!", I was not aware of the
> set and get keywords. Is this syntax supported by both Flash IDE and
> MTASC? Be sure, I'll try that!
>
> to your second 3: "you can use in your example the Asbroadcaster class"
> But I don't have to. The way you use "set x(x:Number)", "get
> x():Number", "setX(x:Number)" and getX():Number", I could just change
> your
>
> public function setX( value:Number ):Void
> {
>     _x = value ;
>     broadcastMessage("onX" , this, _x) ;
> }
>
> into:
>
> public function onX():Void {} // can be dynamically overwritten
> public function setX( value:Number ):Void
> {
>     _x = value ;
>     onX();
> }
>
> ,can't I?
>
> But again: thanks a lot for introducing the set and get keywords to
> me. I'll try that now!
> Thanks,
>
> Matthias
> _______________________________________________
> [email protected]
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
> Brought to you by Fig Leaf Software
> Premier Authorized Adobe Consulting and Training
> http://www.figleaf.com
> http://training.figleaf.com
>


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to