View Full Version : myClass.addEventListener(onChange.Change,func); event, is it possible? How?
donjao
03-06-2008, 11:49 AM
Hi there,
I'm writing my own Dropdown class that extends a MovieClip. Now i need to get id of selected item everytime the selected item is changed. For that, the best idea i could think of is to add addEventListener to my class, so it would know when data is changed inside the class.
Could anyone advice me where to dig? I've been searching for Custom Events, but i can't get idea of how it works.
All the best and thanks in advance! :)
KECrawford
03-06-2008, 12:24 PM
Hi.
Here is a pretty good article on the subject
http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_02.html
If you really want an in depth coverage on it then I would recommend the Essential ActionScript 3.0 book.
I hope that helps.
K.
wvxvw
03-06-2008, 03:41 PM
I usualy create a package for several components, so that I'll have all my custom events in the package like components.evt.* (e.g components.evt.CustomEvt).
This package would contain a class with the list of events names, for e.g. components.evt.EventList
package components.evt {
class EventList{
public static const CUSTOM_EVT:String = 'customEvt';
}
}
package components.evt {
import flash.events.Event;
import EventList;
class CustomEvt{
public var csData:Object;
function CustomEvt(type:String, customData:Object = null){
super(EventList.CUSTOM_EVT);
csData = customData;
}
}
package components {
import flash.display.Sprite;
import components.evt.*;
class CustomComponent extends Sprite {
function CustomComponent(){
}
public function customMethod():void {
dispatchEvent(new CustomEvent('', {message:'hi!'}));
}
}
}
This is very simplified schema, but, should work =)
donjao
03-06-2008, 05:29 PM
Thanks guys for the replies!
You've helped me a lot, with link, book and example!!!
Thanks!
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.