Reputation: 127
Okay I read tons of posts about this but I couldn't find good enough answer. So I have this in my constructor class:
this.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);
this.addEventListener(MouseEvent.MOUSE_UP, mouseup)
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, showInfo);
And I have these 3 functions:
private function mouseup(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, mouseup);
myTimer.reset();
}
private function showInfo(event:MouseEvent):void{
//long press code
}
private function mousedown(event:MouseEvent):void{
myTimer.start();
}
On usual click it does what its supposed to but when it comes to long click (1.5 sec) it echoes this error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::TimerEvent@2ff0bab1 to flash.events.MouseEvent.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.utils::Timer/tick()
Another thing..On normal click there should be one action and on long click another action. My code does both actions on long click. Any advices on how could I make it not run first action on long press? Thank you.
Upvotes: 0
Views: 339
Reputation: 2101
The event type should be TimerEvent, not MouseEvent
private function showInfo(event:TimerEvent):void{
//long press code
}
Upvotes: 1