Skip to main content
April 17, 2009
Answered

Manually dispatching event in as3

  • April 17, 2009
  • 1 reply
  • 1900 views

hi:

how can I simulate events for a demo like in this example:

import flash.events.*;

function traceTxT(e:MouseEvent):void {

  trace("button clicked");

}

blueBtn.addEventListener(MouseEvent.CLICK, traceTxT);

if I add:

blueBtn.dispatchEvent(new Event(MouseEvent.CLICK));

I receive this error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event@1d7eed81 to flash.events.MouseEvent.

at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at dispatcher_fla::MainTimeline/dispatcher_fla::frame1()

thanks in advance

This topic has been closed for replies.
Correct answer kglad

use:

blueBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 17, 2009

use:

blueBtn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

April 18, 2009

thanks a lot, it's working fine now!

kglad
Community Expert
Community Expert
April 18, 2009

you're welcome.