So, I am trying to pass some arguments through a custom MouseEvent. This is my code:
Document Class (Main.as)
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import Events.MyCheckBoxEvent;
/**
* Main Class
* @ purpose: Document class for movie
*/
public class Main extends Sprite{
public function Main(){
//instantiate concrete creators
//var cable1:Page = new Cable1();
var cb:CheckBox = new CustomCheckBox();
addChild(cb);
cb.addEventListener(MyCheckBoxEvent.CLICK, clickHandler, false, 0, ["ted","john","doug"]);
}
private function clickHandler(e:MyCheckBoxEvent){
trace(e.argumentArray);
}
}
}
MyCheckBoxEvent.as
package Events{
import flash.events.MouseEvent;
import flash.events.Event;
public class MyCheckBoxEvent extends MouseEvent {
public static const CLICK:String = "click";
private var _argArray:Array;
public function MyCheckBoxEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, argArray:Array = null) {
super(type,bubbles,cancelable);
_argArray = argArray;
}
public function get argumentArray():Array {
return _argArray;
}
override public function clone():Event{
return new MyCheckBoxEvent(type,bubbles,cancelable,_argArray);
}
}
}
So I dont get any compiler errors at runtime, but when I click on the checkbox I get this error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@10add4a9 to Events.MyCheckBoxEvent.
If I make the argument of the event handler function to be just MouseEvent instead of MyCheckBoxEvent then it works, but it doesnt recognize the _argArray getter… This is driving me mad! I have spent like 3 hours on this already… I tried casting the Event as a MyCheckBoxEvent and same thing…