Flex – ItemRenderer Dispatch Custom Event

I am trying to dispatch a custom event from a custom ItemRenderer

This is my custom event

package events
{
import customClass.Product;

import flash.events.Event;

public class CopyProductEvent extends Event
{
public static const COPY_PRODUCT:String = "COPY_PRODUCT";
public var picked:Prodotti;

public function CopyProductEvent(type:String, picked:Product)
{
super(type);
this.picked = picked;
}
}
}

I have a function in itemRenderer To do this:

private function sendEvent(o:Product):void
{
dispatchEvent(new CopyProductEvent(CopyProductEvent.COPY_PRODUCT,o) );
}

In the main application I have a spark List, I tried to add EventListener to the application and the list itself, but they are never called…

< p>

this.addEventListener(CopyProductEvent.COPY_PRODUCT,
function(e:Product):void{
.. .
});

list.addEventListener(CopyProductEvent.COPY_PRODUCT,
function(e:Product):void{
...
}) ;

Why? ! ? Where did I go wrong?

The event in the function is sent correctly…I can’t intercept it..

It sounds like your event is not bubbling.

Add the bubbles parameter to the Custom event constructor (false by default):

public function CopyProductEvent(type:String, picked:Product, bubbles:Boolean = true)
{
super(type,bubbles);
this.picked = picked;
}

A good explanation of event bubbling in AS3 can be found here:
Event Bubbling in AS3

I am trying to download from Custom ItemRenderer schedules custom events

This is my custom event

package events
{
import customClass.Product;

import flash.events.Event;

public class CopyProductEvent extends Event
{
public static const COPY_PRODUCT:String = "COPY_PRODUCT ";
public var picked:Prodotti;

public function CopyProductEvent(type:String, picked:Product)
{
super(type);
this.picked = picked;
}
}
}

In itemRenderer I have a function to do this:

private function sendEvent(o:Product):void
{
dispatchEvent(new CopyProductEvent(CopyProductEvent.COPY_PRODUCT,o));
}

In the main application I have a spark List, I am trying to add EventListener to the application and the list Themselves, but they are never called…

this.addEventListener(CopyProductEvent.COPY_PRODUCT,
function(e:Product):void{
. ..
});

list.addEventListener(CopyProductEvent.COPY_PRODUCT,
function(e:Product):void{
...
} );

Why? ! ? Where did I go wrong?

The event in the function is sent correctly…I can’t intercept it..

It sounds like your event is not bubbling.

Add the bubbles parameter to the Custom event constructor (false by default):

public function CopyProductEvent(type:String, picked:Product , bubbles:Boolean = true)
{
super(type,bubbles);
this.picked = picked;
}

About the incident in AS3 A good explanation of Bubbling can be found here:
Event Bubbling in AS3

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 5841 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.