Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > ActionScript

  • Print
  • + Share This
From the author of

Mouse events

Problem: Button and movie clip handlers such as onRelease, onPress and onReleaseOutside no longer exist in ActionScript 3.

Solution: ActionScript 3 is all about events, the MouseEvent class is used to control what the button and movie clip handlers controlled in ActionScript 2.

Code: Using the B class above we are now importing the MouseEvent class and adding an event listener to the constructor. The event listener has been added to the stage, which means that any time the mouse is down our custom class method, mouseDown, will be triggered. This functionality produces the same results as the onPress handler from ActionScript 2, but, in addition, detailed information about the event is also passed to the custom class method that is triggered.

package
{
    import flash.events.MouseEvent;
    
    public class B extends A
    {
        public function B():void
        {
            super();
            stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
        }
        
        private function mouseDown(event:MouseEvent):void
        {
            trace(event);
        }
    }
}
  • + Share This
  • 🔖 Save To Your Account