SimpleMouseEvents (onReleaseOutside, onDragOut,…)
May 21st, 2007
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
Filed under: actionscript
25 Responses to “SimpleMouseEvents (onReleaseOutside, onDragOut,…)”
-
Andrew Says:
May 24th, 2007 at 10:14 pmI’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?
-
André Michelle Says:
May 25th, 2007 at 8:04 amWhat is your target? Make sure that the target property buttonMode must have the value ‘true’.
-
zguillez Says:
June 1st, 2007 at 11:48 amWow! great work, thanks ;)
-
swallow.sz Says:
June 21st, 2007 at 3:29 amthanks, this is what I need.
-
Rafeo Says:
July 9th, 2007 at 5:24 pmSo many thanks!! Just what I need too!!
-
Daniel Says:
October 26th, 2007 at 4:12 pmWonderful :)
-
Daniel Says:
December 19th, 2007 at 2:09 pmHi 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 ;)
-
Rasso Says:
February 26th, 2008 at 6:53 pmHey 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! -
cathelper Says:
April 1st, 2008 at 12:03 amHi 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.
-
Jed Says:
November 18th, 2008 at 6:21 pmYep, 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.
-
Jed Says:
November 18th, 2008 at 6:25 pmSorry, got that wrong: the CS3 components continually set stage.focus to themselves, rather than null.
-
Jed Says:
November 18th, 2008 at 6:39 pmSolution 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?
-
xtyler AS3 Button Behavior Made Easy Says:
January 30th, 2009 at 3:18 am[...] implemented 3 new events: stateUp, stateOver and stateDown. Andre Michelle wrote on this same subject almost 2 years ago and posted a similar solution. I took the opportunity to review his and it works [...]
-
OnReleaseOutside in AS3 Says:
March 7th, 2009 at 5:43 pm[...] you don’t have to write that becouse Andre Michelle did it already, thanks for him! His SimpleMouseEvents is a very useful and easy-to-use class that can be handle onReleaseOutside, onDragOut and [...]
-
Artem Brigert Says:
July 21st, 2009 at 5:53 pmDankeschön ! :)
-
sir Says:
October 14th, 2009 at 4:31 pmHow 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); -
sir Says:
October 14th, 2009 at 4:34 pmI 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() -
Thijs Says:
October 28th, 2009 at 6:48 pmThere’s no license file included in the files so can I assume they’re in the public domain?
-
SimpleMouseEvents (onReleaseOutside, onDragOut,…) : Joan Garnet :: Arquitectura y desarrollo RIA Says:
January 1st, 2010 at 8:40 pm[...] al post y descarga: * SimpleMouseEvents May 23, 2007 | Filed Under ActionScript, Flash [...]
-
david saenz Says:
January 15th, 2010 at 12:27 amDO 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???
-
Greg Gavutis Says:
January 27th, 2010 at 5:14 pmConfirm 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”);
} -
onReleaseOutside-Workaround klappt nicht - Flashforum Says:
June 7th, 2010 at 3:47 pm[...] hab in nem aktuellen Projekt das hier verwendet: Andre Michelle Blog Archive SimpleMouseEvents (onReleaseOutside, onDragOut,…) Funktioniert gut. __________________ RTFM Wie man Fragen richtig stellt. Achim Bindannmalweg [...]
-
fanny Says:
June 8th, 2010 at 4:21 pmthanks a lot, that saved me so much time and thinking!
-
[Flash CS5] - onReleaseOutside - Flashforum Says:
June 14th, 2010 at 10:22 am[...] [...]
-
Manolito Says:
July 5th, 2010 at 10:14 amThanks so much from Spain Andre! You save my live…
And lucky for the next World Cup match Germany – Spain ;-)