I have a class with ADDED_TO_STAGE event (it's an incomplete dialog), and I want it to return a value. Is this possible? Or what's the what's the way I should follow?
My class: http://sudrap.org/paste/text/555684/
Edit: I'll create some buttons in the class. I want buttons' functions to return some value. And I'll need to get which button is clicked. I want to pass these values to main fla.
I'll probably need the class to return an array for settings specified in the dialog.
You can do this by creating your custom event class that extends Event
and pass your required parameters within.
package{
import flash.events.Event;
public class CustomEvent extends Event{
public static const PASS_PARAMS:String = "passParams";
// Your custom properties.
public var btnName:*;
public function CustomEvent(type:String, bName:*, bubbles:Boolean=false, cancelable:Boolean=false):void {
this.btnName = bName;
super(type, bubbles, cancelable);
}
override public function clone():Event{
return new CustomEvent(type,btnName, bubbles, cancelable);
}
}
}
and dispatch your customEvent
on button click event whenever happens
btn.addEventListener(MouseEvent.CLICK, onBtnClick);
private function onBtnClick(e:MouseEvent):void{
dispatchEvent(new Event(CustomEvent.PASS_PARAMS, e.target.name));
}
and add a listener on your Main class
this.addEventListener(CustomEvent.PASS_PARAMS, onProcessedEvent);
private function onProcessedEvent(e:CustomEvent):void{
trace(e.btnName);
}