onReleaseOutside: AS3 Button Engine revisited
September 22nd, 2007 by LuisA few months ago I wrote a post with a solution to the missing onReleaseOutside event in AS3.
Unfortunately the post has disappeared completely while upgrading some wordpress plugins.
Here there is a resume of the post, a swf demo and the source code of the Button engine that allows you to set sprites as buttons very easily, with some additional events such onReleaseOutside, onRollOutWhileMouseDown, onRollOverWhileMouseDown and the ability to manage in a very natural and intuitive way all the Button Instances in your project.
Download src code.
Simple Usage:
Actionscript:
- package
- {
- import com.lessrain.as3lib.utils.stage.TopLevel;
- import flash.display.Sprite;
- import com.lessrain.as3lib.controls.button.Button;
- import com.lessrain.as3lib.controls.button.ButtonEvent;
- import com.lessrain.as3lib.controls.button.ButtonList;
- import com.lessrain.as3lib.controls.button.ButtonListEvent;
- public class Test extends Sprite
- {
- private var _myButton : Button;
- private var _mySprite : Sprite;
- public function Test()
- {
- TopLevel.getInstance().stage = this.stage;
- initialize();
- }
- public function initialize():void
- {
- ButtonList.getInstance().addEventListener(ButtonListEvent.BUTTON_ADDED,buttonAddedToList);
- ButtonList.getInstance().addEventListener(ButtonListEvent.BUTTON_REMOVED,buttonRemovedFromList);
- _mySprite = new Sprite();
- _mySprite.graphics.beginFill(0x660000);
- _mySprite.graphics.drawCircle(250,250,50);
- _mySprite.graphics.endFill();
- addChild(_mySprite);
- _myButton = new Button();
- _myButton.addEventListener(ButtonEvent.RELEASE,release);
- _myButton.addEventListener(ButtonEvent.RELEASE_OUTSIDE,releaseOutside);
- _myButton.addEventListener(ButtonEvent.PRESS,press);
- _myButton.addEventListener(ButtonEvent.ROLL_OVER,rollOver);
- _myButton.addEventListener(ButtonEvent.ROLL_OUT,rollOut);
- _myButton.addEventListener(ButtonEvent.ROLL_OVER_WHILE_DOWN,press);
- _myButton.addEventListener(ButtonEvent.ROLL_OUT_WHILE_DOWN,rollOutWhileDown);
- _myButton.initialize(_mySprite,'myID','myGroup',false,true);
- }
- private function press(event_:ButtonEvent):void
- {
- trace(String(event_.type));
- }
- private function release(event_:ButtonEvent):void
- {
- trace(String(event_.type));
- }
- private function releaseOutside(event_:ButtonEvent):void
- {
- trace(String(event_.type));
- }
- private function rollOutWhileDown(event_:ButtonEvent):void
- {
- trace(String(event_.type));
- }
- private function rollOver(event_:ButtonEvent):void
- {
- trace(String(event_.type));
- }
- private function rollOut(event_:ButtonEvent):void
- {
- trace(String(event_.type));
- }
- private function buttonAddedToList(event_:ButtonListEvent):void
- {
- var myButton:Button = event_.getButton() as Button;
- trace('--------------------------------------------------');
- trace('Button has been added to the ButtonList:');
- trace('Button GroupID: '+Button(event_.getButton()).groupID);
- trace('Button ID: '+Button(event_.getButton()).id);
- trace('--------------------------------------------------');
- }
- private function buttonRemovedFromList(event_:ButtonListEvent):void
- {
- trace('button has been removed:'+event_.currentTarget);
- }
- }
- }
Related Links:
- SimpleMouseEvents (onReleaseOutside, onDragOut,…), Andre Michelle.
- AS3: Where is my onReleaseOutside, code zen.
- Handling onReleaseOutside in AS3 / flex, Eric Cancil.
- Wherefore Art Thou onReleaseOutside?, Automata on ActionScript.
- Custom event for "onReleaseOutside", Kirupa Forum.
- SimpleButton, Flash Obscura


September 24th, 2007 at 3:46 am
[…] moving when you release the mouse button. Get it here. Updated the class Related links: lessrain - AS3 Button Engin revisted Share and Enjoy:These icons link to social bookmarking sites where reade […]
December 17th, 2007 at 4:37 pm
[…] re are some classes that manage global contol of your various button states. very useful:- http://www.blog.lessrain.com/?p=5 […]
May 25th, 2008 at 7:08 pm
Thanks for sharing! Looks nice, i wonder why they left the onReleaseOutside out of AS3… I have some serious problems with this…
Kind regards,
Jankees
July 11th, 2008 at 9:41 pm
I’m using firefox on a mac and your example doesnt fully work. The release outside only registers if I release inside the plugin space. If I release outside the stage then nothing is triggered. Back in as2 this used to work. There has to be a solution for as3.
July 18th, 2008 at 8:59 am
Thanks
April 2nd, 2009 at 11:21 am
does anyone have a solution for what paul said!
no one seems to have a solution for that!
April 17th, 2009 at 5:27 pm
@zotos I think the onReleaseOutside is now MOUSEUP or MOUSELEAVE events:
yourmc.addEventListener(MouseEvent.MOUSEDOWN, onMouseDown);
function onMouseDown(e:MouseEvent):void
{
var target:Object = e.currentTarget;
target.startDrag(true, new Rectangle(0, 5, 0, 195));
stage.addEventListener(MouseEvent.MOUSEUP, function():void {
target.stopDrag();
});
stage.addEventListener(Event.MOUSELEAVE, function():void {
target.stopDrag();
});
}
October 29th, 2009 at 8:42 pm
[…] onReleaseOutside: AS3 Button Engine revisited […]