[FF]: mouse 'n' stuff

by bradsedito forked from mouse 'n' stuff (diff: 36)
♥0 | Line 57 | Modified 2011-08-29 05:40:01 | MIT License
play

ActionScript3 source code

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/b1vi
 */






package 
{
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;
    import com.greensock.easing.*;
    import com.greensock.*;
    
    
    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, 10); //  ( DO_X, DO_Y, SIZE )
            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, 0x131413);
            sh.graphics.drawCircle(16, 16, 20);
            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 
        {
            TweenMax.to(a, 1.0, {x:mouseX, y:mouseY, ease:Cubic.easeOut});
            TweenMax.to(b, 2.0, {x:mouseX, y:mouseY, ease:Cubic.easeOut});
//          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
        }
        
    }//end class
}//end package