Laxmidi
Laxmidi

Reputation: 2684

Problem with an Event in a Custom Component

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

Upvotes: 0

Views: 327

Answers (1)

JeffryHouser
JeffryHouser

Reputation: 39408

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.

Upvotes: 3

Related Questions