Wow, this is exactly what I needed. Thank you very very much!

--- In [email protected], Scott Melby <[EMAIL PROTECTED]> wrote:
>
> Kenny -
> 
> Your component needs to be an EventDispatcher... if it is extending an 
> existing DisplayObjects, then it already is.  If not, you can just 
> extend EventDispatcher yourself.  Then your component can notify
parents 
> etc. by creating an event of the appropriate type and dispatching.  For 
> instance here is an event you could dispatch on change:
> 
> //create a change event and notify...
> var evt:Event = new Event(Event.CHANGE, true, false);
> this.dispatchEvent(evt);
> 
> Note: You may or may not want the event to bubble... that will
depend on 
> whether or not the listener is attached directly to your component (or 
> one of its ancestors).
> 
> 
> 
> If you want to send data out with the click you can create a new custom 
> event (extend Event) and add your data property... then instantiate
your 
> custom event type and dispatch one of those instead.  Example:
> 
> public class MyEvent extends Event
> {
>     public static const TYPE:String = "myEvent";
>     public var eventData:Object = null; 
> 
>     public function MyEvent(data:Object, bubbles:Boolean = false, 
> cancellable:Boolean = false)
>     {
>         super(MyEvent.TYPE, bubbles, cancellable);
>         this.eventData = data;
>     }
> }
> 
> and in your click handler:
> 
> var evt:MyEvent = new MyEvent(myData, true);
> this.dispatchEvent(evt);
> 
> The code that listens for this custom event can just do something like:
> 
> //attach to the component and listen for a MyEvent type event
> myComponent.addEventListener(MyEvent.TYPE, handleMyEvent, false, 0,
true);
> 
> public function handleMyEvent(event:MyEvent):void
> {
>    //handle the event...
> }
> 
> hth
> Scott
> 
> Scott Melby
> Founder, Fast Lane Software LLC
> http://www.fastlanesw.com
> http://blog.fastlanesw.com
> 
> 
> 
> kenny14390 wrote:
> > How can I make the custom component tell the parent when it was
> > clicked? I can't figure out how to make them communicate except for
> > the parent making a new custom component and setting its properties.
> > I'd like to get an event or a function call when the component is
> > clicked (mouseDown). Thanks.
> >
> >
> >
>


Reply via email to