Hard to say from the code snippets, but it looks like your button is
listening for addItemEvent on itself, but it is the app that is
dispatching

 

________________________________

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of pbrendanc
Sent: Sunday, July 06, 2008 2:28 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Problem Adding Custom Event Listeners in a
component?

 

I have a custom button on which I want to listen to some custom
events. For some reason in the following code my custom events are
never heard/triggered.

1)In the button's constructor I added the listeners as follows:

// Custom Class Code
public class testButton extends Button
{
//constructor 
public function testButton {
addEventListener (MouseEvent.MOUSE_OVER, handleMouseOver); 
// custom event
addEventListener("addItemEvent", handleAddItemEvent); 
}
public function handleMouseOver (event:MouseEvent):void { 
// display as a tooltip
this.toolTip = "Say Cheese";

public function handleAddItemEvent():void { 
// display as a tooltip
Alert.show ("testButton Event: Add Item Event");

2) Parent Form Code (app.mxml)

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

// Code in test button to dispatch custom event
// 
private function triggerEventHandler():void { 
//Alert.show ("Broadcast Event");
dispatchEvent(new Event("addItemEvent",true));
}

This looks like it should work, but only the MouseOver event is ever
fired - am I missing something obvious?

TIA
Patrick

 

Reply via email to