It's fairly straightforward.. at least it is if what I'm about to show you
is what you want to know. In your class file follow this basic structure.
You'll need to import mx.events.EventDispatcher and add the three functions
at the bottom to any class you wish to broadcast from.

import mx.events.EventDispatcher;
class SampleClass {
    function SampleClass() {
        //Register
        mx.events.EventDispatcher.initialize(this);
    }

    public function someFunction():Void {
        //Build an event object. Type is the name of the callback function
you'll use. (listener.onDragRelease)
        var eventObject:Object = {target:this, type:'onDragRelease'};
        //You can also add variables to pass into the event
        eventObject.position = getDropPosition();
        //Send it away!
        dispatchEvent(eventObject);
    }
    /**
        *        dispatchEvent
        *
        *        Used to dispatch events
        *
        */
    function dispatchEvent() {
    }
    function addEventListener() {
    }
    function removeEventListener() {
    }
}

To listen to those events you just need to add a listener that is listening
for the event name you defined in the event object as type:

applicationListener = new Object;
applicationListener.onDragRelease= function(eventObj) {
            //trace(":: onDragRelease Event Recieved!");
            //trace(eventObj.position);
            //Do something here with the data
}
var someObject:Object = {};
someObject.addEventListener("onDragRelease",applicationListener);


Hope that helps you.


On 12/30/05, Mark Ribau <[EMAIL PROTECTED]> wrote:
>
> Does anyone know of a really really good example that shows how to write
> Components that dispatch and listen to events ?
>
> Deeper question: What about a Component that when dragged onto another
> Component/Object adds listeners for that Component's Events to the
> Component/Object ?
>
> Any and all assistance is appreciated.
> --
> Mark Ribau
> Lead Windows Developer | My Tech Blog
> <http://www.redbugtech.com/blogs/mark.php>
> Redbug Technologies, Inc. <http://www.redbugtech.com> - www.redbugtech.com
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>



--
Spencer Markowski
The Able Few
[EMAIL PROTECTED]
314.631.5576
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to