Native Custom Cursors in Flash Player 10.2 using the new MouseCursorData object

December 1st, 2010 by Adrian

Native Custom Cursors

At last, Flash Player 10.2 Beta introduces (among other things) native custom cursors. This is one of those small features that doesn’t get headline news (unlike Stage Video) but is something developers have been requesting for ages, will make our lives a bit easier and will improve the end-user experience.

Thibault Imbert has a post on his blog showing and example of how the new MouseCursorData object and API will work.

Posted in ActionScript 3.0, Adobe, Flash | 2 Comments »

Make your cursor always point to the middle of the screen

August 14th, 2009 by Adrian

Yesterday I was taking a look at Balsamiq Mockups and liked the way that the mouse always pointed to the centre of the screen when in fullscreen mode. So I thought I’d quickly knock something to together that did this, and share it here.

It’s pretty simple stuff, but handy to have available to copy-and-paste, if you need something similar.

The code is all in the document class …

package
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;

    public class Main extends MovieClip
    {
       
        private var mouseIsOverStage:Boolean;
        private var arrow:Arrow;

        public function Main():void
        {
            arrow = new Arrow();
            Mouse.hide();
            stage.addEventListener(Event.MOUSE_LEAVE, onStage_MOUSE_LEAVE);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onStage_MOUSE_MOVE);
        }
       
        private function onStage_MOUSE_LEAVE(event:Event):void
        {
            mouseIsOverStage = false;
            removeChild(arrow);
        }
       
        private function onStage_MOUSE_MOVE(event:MouseEvent):void
        {
            if (!mouseIsOverStage) {
                mouseIsOverStage = true;
                onStage_MOUSE_ENTER();
            }
            arrow.x = stage.mouseX;
            arrow.y = stage.mouseY;
            var dx:Number = arrow.x - stage.stageWidth/2;
            var dy:Number = arrow.y - stage.stageHeight/2;
            var radians:Number = Math.atan2(dy, dx);
            arrow.rotation = radians * 180/Math.PI;
            event.updateAfterEvent();
        }
       
        private function onStage_MOUSE_ENTER():void
        {
            arrow.x = stage.mouseX;
            arrow.y = stage.mouseY;
            addChild(arrow);
        }
       
    }

}

Download the source files here

Posted in ActionScript 3.0, Sample Code | No Comments »

Hiding the cursor in AS3

April 1st, 2008 by Adrian

To hide the mouse cursor using AS3 use this …

package {
    import flash.display.Sprite;
    import flash.ui.Mouse;

    public class Main extends Sprite
    {
        public function Main():void
        {
            Mouse.hide();
        }
    }
}

Posted in ActionScript 3.0, Flash, Sample Code | 3 Comments »