I am not sure if something is wrong with my code or if I have to handle the error differently. I have an instance of Gear and the other one is bLine. I am trying to make both move as soon as the gear falls on the line. So what I have inside of the instance coded is:
var ev2:Event = new Event("transfer");
dispatchEvent(ev2);
stop();
In the bLine I have: `
import flash.events.Event;
this.addEventListener(Event.ENTER_FRAME,Move);
function Move(e:Event):void {
this.x=this.x+3;
};
Then, in the main timeline:
import flash.events.Event;
gear.addEventListener("transfer",transferGear);
function transferGear(e:MouseEvent) {
bLine.gotoAndPlay(2);
};
This is the output I'm getting: "TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@16bbd6bb7821 to flash.events.MouseEvent. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent()
at Rube2_fla::mc_gear_4/frame24()"
So what am I doing wrong and how I could fix it?
(e:Event)
or even(e:Event = null)
instead of (e:MouseEvent). Your gear.addEventListener has no mouse events defined so later the functiontransferGear
cannot be told to expect input of typeMouseEvent
– VC.One(e:Event = null)
it allows you to also use same function even at those times when not involving some event. For that just do atransferGear();
anytime to makebLine
go to frame 2. – VC.One