SimpleMouseEvents (onReleaseOutside, onDragOut,…)

Some of the most confronted issues in AS3 are the missing mouse events as onReleaseOutside, onDragOut, onDragOver and so on. I saw that question over all boards. While coding the TR909, I had the same problem and I tried to figure out a common solution. I wrote a wrapper class, which adds itself as a listener to the passed target object. It takes care of the fact, that the stage can be null (required for releaseOutside) and the stage focus. It also provides (if necessary) the trackAsMenu mode to receive onDragOut, onDragOver, if the target itself doesn’t have the focus.

source code + sample application

26 thoughts on “SimpleMouseEvents (onReleaseOutside, onDragOut,…)”

  1. I’m having trouble getting the RELEASE functionality working. Everything seems to work fine. I copied the code over directly from the Main.as that came with the zip.

    Any suggestions/bug comments?

  2. Hi Andre,

    when using cs3 components the RELEASE Event seems to fail. I could nail it down to a focus problem. AFAIK the components use their own focus-management, which seems to interfere the ‘target.stage.focus’ property.

    if( target.stage.focus == target )
    // is never fired when using components
    dispatch(SimpleMouseEvent.RELEASE);

    without this condition the event is fired normally…but that can’t be the solution ;)

  3. Hey André, first of all thanks for this nice class! I used it before here and everything worked fine (in this case, I wrote everything in one Main-Class).
    Now I’m trying to use it again in a sub-Class, but my Button (on the stage) doesn’t respond, even if it obviously gets registered (the hand-cursor appears)…
    I would be very grateful for your help!

  4. Hi Andre, i’d like to thank you for this wonderful piece of work. It helped us a lot.

    One question, i’m having the same problem with components as Daniel posted on December 19th.

    You can take a look at the problem in

    http://www.malldelsol.mash.com.ec

    If you click on ‘eventos’ the buttons for scrolling use the events class and work.

    But…if you click on ‘locales comerciales’ before entering ‘eventos’ then the buttons fail to get the RELEASE event.

    I isolated the problem on the presence of flash components ‘Combo’ and/or ‘List’. Even tough i exit ‘locales comerciales’ it seems that the problem still exists.

    Any comment on this would be very appreciated.

    Thanks for all the support.

  5. Yep, running into the same problem with the CS3 components as the above posters. Looks like they clobber the stage.focus property by continually setting it to null. The problem only exhibits itself once a component has been added to the display list.

  6. Solution for CS3 components issue: listen to the traditional MouseEvent.MOUSE_UP instead of the missing SimpleMouseEvent.RELEASE, while continuing to leverage Andre’s SimpleMouseEvent.RELEASE_OUTSIDE as per normal … right?

  7. How do you remove the SimpleMouseEventHandler listeners? I have a situation where I have to remove the movie clip and I get an error:

    Cannot access a property or method of a null object reference.
    at BodyPart/dropMeOutside()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at de.popforge.events::SimpleMouseEventHandler/dispatch()
    at de.popforge.events::SimpleMouseEventHandler/onStageMouseUp()

    Tried this but no dice:

    SimpleMouseEventHandler.unregister(this);
    parent.removeChild(this);

  8. I minimized the error this way:

    SimpleMouseEventHandler.unregister(this);
    this.removeEventListener(SimpleMouseEvent.RELEASE_OUTSIDE, dropMeOutside);
    parent.removeChild(this);

    but still get this:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at de.popforge.events::SimpleMouseEventHandler/onTargetMouseUp()

  9. DO you have an example of this with .fla

    For some reason I can’t get it to work and it seems simple enough.

    import SimpleMouseEvents.*;

    test_movie_mc.buttonMode = true;
    test_movie_mc.useHandCursor = true;

    test_movie_mc.addEventListener(SimpleMouseEvent.RELEASE_OUTSIDE, test_release_outside);
    //test_movie_mc.addEventListener(MouseEvent.CLICK, test_release_outside);

    function test_release_outside(event:MouseEvent):void
    {
    trace(“test_release_outside”);
    }

    Am I missing something???

  10. Confirm that SimpleMouseEventHandler is being imported via your wildcard directive (de.popforge.events.SimpleMouseEventHandler)

    Don’t forget to register your object:

    SimpleMouseEventHandler.register(test_movie_mc);

    And be sure to ‘type’ the event argument properly (SimpleMouseEvent vs. MouseEvent) in your test function to avoid errors:

    function test_release_outside(event:SimpleMouseEvent):void
    {
    trace(“test_release_outside”);
    }

Comments are closed.