views:

29

answers:

1

Hi,

I'm just getting started with custom events in a custom component. And I don't quite have the hang of it, yet.

I've got a component with a button in it. When it's clicked, I want to call a function in the main app.

Custom Component:

<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute"  >


<mx:Metadata>
    [Event(name="goClick", type="mx.events.Event")]
</mx:Metadata>

<mx:Script>
        <![CDATA[

    private function onButtonClickHandler(event:MouseEvent):void {
        dispatchEvent(new Event("goClick"));
    }
        ]]>
</mx:Script>

      <mx:Button id="myGoButton" label="Go"  
          click="onButtonClickHandler(MouseEvent)"  />

</mx:Panel>

Main App:

<myFolder:MyComponent
    goClick="MyCoolFunction()">

Unfortunately, I'm doing something wrong. It says that the Event type is unavailable. What do I need to change or add? My guess is that I need to declare goClick in some way?

Thank you!

-Laxmidi

+1  A: 

No such class as mx.events.Event unless you created one. Change that to flash.events.Event and you'll be good to go.

If you did create an 'mx.events.Event" class, make sure that your dispatch event is create an instance of your custom class and not the flash.events.Event.

www.Flextras.com
Hi www.Flextras.com, Thanks for the great explanation. I learned something.
Laxmidi
You're Welcome! Glad to help
www.Flextras.com