In general, you have to be listening to the object that is dispatching.
If you use bubble or capture, you can listen to parents if they are
display objects.

 

3 siblings would need to know about each other and listen to each other.
Having them register with a central object that dispatches on their
behalf or they dispatch from might be better.  That's how
RadioButton/RadioButtonGroup work.

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of pbrendanc
Sent: Sunday, July 06, 2008 4:29 PM
To: [email protected]
Subject: [flexcoders] Re: Problem Adding Custom Event Listeners in a
component?

 

I think I need some additional clarification here as I'm not sure why
this is not OK- (I expect the button to respond to the custom event
regardless of who dispatched this event).

Imagine 3 buttons in a grid: B1, B2,B3. Clicking on any button and
updates the appearance (e.g. label color) of the other 2 buttons (i.e.
everyone else but the clicked button). Do this w/out any hard coding 
the names in click events etc. - each button gets a list of dependent
btn ID's - if you are on the list update yourself, otherwise ignore.

What I need to do here is to have the containing (parent??) form
intercept (override?) the button click event, perform some preprocessing
(e.g. build a list) and forward this list by dispatching a custom event
. (In the example below you can see that clicking a button affects
other buttons.

Where I'm stuck is on how best to setup the listeners ,and intercept
the parent button click event. Per my previous message the custom
handler on the button is never triggered.

(Maybe I'm missing the wood for the tree's here - however it's a good
exercise that will solidify my understanding of the Flex event model)

TIA,
Patrick

--- [EMAIL PROTECTED] <mailto:Inflexcoders%40yahoogroups.com>
, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> 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: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
]
On
> Behalf Of pbrendanc
> Sent: Sunday, July 06, 2008 2:28 AM
> To: [email protected] <mailto:flexcoders%40yahoogroups.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