In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

mouse 'n' stuff

The native cursor fast. (gray ring)
Even when the stage frame rate is low, we can have the Flash Player redraw after certain events. (MOUSE_MOVE moves black dot and requests redraw)
The text value only changes on ENTER_FRAME events.

For me, the dot is a little bit behind the ring.
Get Adobe Flash player
by wh0 11 Jul 2011
    Embed
/**
 * Copyright wh0 ( http://wonderfl.net/user/wh0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/saZ0
 */

package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;
    public class FlashTest extends Sprite {
        
        private var a:Shape;
        private var b:Shape;
        
        public function FlashTest() {
            // the dot: moves on ENTER_FRAME event
            a = new Shape();
            a.graphics.beginFill(0x000000);
            a.graphics.drawCircle(0, 0, 6);
            addChild(a);
            stage.addEventListener(Event.ENTER_FRAME, frame);
            
            // the small ring: moves with the mouse
            b = new Shape();
            b.graphics.lineStyle(4, 0x000000);
            b.graphics.drawCircle(0, 0, 8);
            addChild(b);
            stage.addEventListener(MouseEvent.MOUSE_MOVE, move);
            stage.addEventListener(Event.MOUSE_LEAVE, leave);
            
            // the large ring: native cursor
            var bd:BitmapData = new BitmapData(32, 32, true, 0x00000000);
            var sh:Shape = new Shape();
            sh.graphics.lineStyle(4, 0x000000);
            sh.graphics.drawCircle(16, 16, 12);
            bd.draw(sh);
            var mcd:MouseCursorData = new MouseCursorData();
            mcd.data = new Vector.<BitmapData>(1);
            mcd.data[0] = bd;
            mcd.hotSpot = new Point(16, 16);
            Mouse.registerCursor('ring', mcd);
            Mouse.cursor = 'ring';
        }
        
        private function frame(e:Event):void {
            a.x = mouseX;
            a.y = mouseY;
        }
        
        private function leave(e:Event):void {
            a.visible = false;
            b.visible = false;
            // can't updateAfterEvent(); dot lingers for up to a second
        }
        
        private function move(e:MouseEvent):void {
            a.visible = true;
            b.visible = true;
            b.x = e.stageX;
            b.y = e.stageY;
            e.updateAfterEvent(); // request redraw
        }
        
    }
}