Hey all I’m working on a ROLL_OVER event class and I’m stuck on an Error. Not sure what it is that I’m missing.
Error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@2f6d661 to myCustomEvent.
My myCustomEvent
package {
import flash.events.Event;
public class myCustomEvent extends Event {
// CONSTANTS
public static const ROLL_OVER:String = 'rollOver';
public static const CLICK:String = 'click';
// VARS
private var _body;
// GETTERS/SETTERS
public function get body() { return _body; }
// CONSTRUCTOR
public function myCustomEvent(type:String, body, bubbles:Boolean=true, cancelable:Boolean=false){
_body = body;
super(type, bubbles, cancelable);
//
trace("type:"+type+" bubbles:"+bubbles+" cancelable:"+cancelable);
trace("body.name:"+body.name+", pram1:"+body.pram1+", pram2:"+body.pram2);
}
// PUBLIC METHODS
override public function clone():Event {
return new myCustomEvent( type, body, bubbles, cancelable );
}
}
}
package{
//
//*********** IMPORTS **********//
import flash.events.Event;
import flash.display.Sprite;
import flash.display.Shape;
//
//*********** IMPORTS **********//
//
public class eventTest extends Sprite {
private var thumContaner:Sprite;
private var thumBack:Shape;
private var thumArray:Array = new Array(0, 1, 2, 3, 4, 5, 6);
private var thumObject:Object;
private var thumID:Number = 0;
private var thumX:Number = 0;
private var thumGutter:Number = 10;
private var thumName:String;
public function eventTest():void {
for each (var thumItems in thumArray){
thumContaner = new Sprite();
thumContaner.name = "thumContaner_"+thumID;
thumName = thumContaner.name;
trace("thumName: "+thumName);
thumContaner.y = 300;
thumContaner.x = thumX;
thumContaner.alpha = 0.6;
addChild(thumContaner);
//
thumBack = new Shape();
thumBack.graphics.beginFill(0x666666);
thumBack.name = "thumBack";
thumBack.graphics.drawRect(0, 0, 56, 56);
thumBack.graphics.endFill();
thumBack.alpha = 0.6;
thumContaner.addChild(thumBack);
thumX = (thumX+thumGutter)+thumBack.width;
// thum Object
thumObject = {name:thumName, pram1:thumX, pram2:thumID};
//
thumContaner.addEventListener( myCustomEvent.ROLL_OVER, _EventROLL_OVER );
dispatchEvent( new myCustomEvent( myCustomEvent.ROLL_OVER, thumObject ) );
thumContaner.addEventListener( myCustomEvent.CLICK, _EventCLICK );
dispatchEvent( new myCustomEvent( myCustomEvent.CLICK, thumObject ) );
thumID++
}
}
private function _EventROLL_OVER( e:myCustomEvent ):void {
trace("body.name:"+e.body.name+", pram1:"+e.body.pram1+", pram2:"+e.body.pram2);
}
private function _EventCLICK( e:myCustomEvent ):void {
trace("body.name:"+e.body.name+", pram1:"+e.body.pram1+", pram2:"+e.body.pram2);
}
}
}
This is what is trace output.
Output:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::MouseEvent@2f6d661 to myCustomEvent.
Thanks
Scott