-
Event Problems
I'm currently having a weird problem with a couple events in an app I'm making.
What I'm trying to achieve is when a user double clicks a thumbnail on the stage to trigger the onDoubleClick and when a user clicks once on a thumbnail trigger onClick both of which are inside a screen class which the thumbnails will be inside of.
I only want the single click to trigger if the double click hasn't.
I have it working but I have a little problem in the debug window that I cant see why its happening.
Here is the setup;
The part of the Screen class that creates the thumbnail and adds its listeners
PHP Code:
var thumb:Thumbnail = new Thumbnail();
thumb.addEventListener(Thumbnail.THUMB_CLICK, onClick);
thumb.addEventListener(Thumbnail.THUMB_DOUBLE_CLICK, onDoubleClick );
Here is the functions
private function onClick(e:Event) {
trace("clicked");
}
private function onDoubleClick(e:Event) {
trace("double clicked");
}
Now here is the guts of the Thumbnail class
PHP Code:
public class Thumbnail extends MovieClip {
public static const THUMB_DOUBLE_CLICK:String = "double_click";
public static const THUMB_CLICK:String = "click";
var timer:Timer;
public function Thumbnail() {
addEventlistener( MouseEvent.CLICK, onClick);
addEventlistener( MouseEvent.DOUBLE_CLICK, onDoubleClick);
}
private function onClick(e:MouseEvent) {
timer = new Timer(250,1);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();
}
private function onDoubleClick(e:MouseEvent) {
if(timer != null) {
timer.stop();
timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer = null;
dispatchEvent(new Event(THUMB_DOUBLE_CLICK));
}
}
private function onTimerComplete(e:TimerEvent) {
dispatchEvent(new Event(THUMB_CLICK));
}
}
Now it all works fine but I get a Error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.events::Event to flash.events.MouseEvent
Now I cannot see anywhere were I'm event trying to cast an event from Event to MouseEvent.
The error says its happening at the onTimerComplete function.
Any thoughts?
-
Very weird, I think I found the problem.
I changed
public static const THUMB_DOUBLE_CLICK:String = "double_click";
public static const THUMB_CLICK:String = "click";
too
public static const THUMB_DOUBLE_CLICK:String = "double_click";
public static const THUMB_CLICK:String = "single_click";
Even though I have no listners for mouse event one gets triggered and it must have the same string as "click".