A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Event Problems

  1. #1
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254

    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_CLICKonClick);
    thumb.addEventListener(Thumbnail.THUMB_DOUBLE_CLICKonDoubleClick );

    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() {

    addEventlistenerMouseEvent.CLICKonClick);
    addEventlistenerMouseEvent.DOUBLE_CLICKonDoubleClick);

    }

    private function 
    onClick(e:MouseEvent) {

    timer = new Timer(250,1);
    timer.addEventListener(TimerEvent.TIMER_COMPLETEonTimerComplete);
    timer.start();

    }

    private function 
    onDoubleClick(e:MouseEvent) {

    if(
    timer != null) {

    timer.stop();
    timer.removeEventListener(TimerEvent.TIMER_COMPLETEonTimerComplete);
    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?
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

  2. #2
    Dance Monkey Dance! Doush.'s Avatar
    Join Date
    Jun 2004
    Posts
    254
    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".
    "I layed down in my bed last night looked up at the stars, and thought to myself... Where the F*#K is my roof"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center