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

Move to Mouse

Get Adobe Flash player
by RTLShadow 26 Oct 2011
/**
 * Copyright RTLShadow ( http://wonderfl.net/user/RTLShadow )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/k7uq
 */

// forked from cemevin's flash on 2011-10-25
package {
    import flash.text.TextField;
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        
        private var mx:Number=200;
        private var my:Number=100;
        private var mcPlayer:MovieClip = new MovieClip();
        private var myText:TextField = new TextField();
        
        private function drawPlayer():void{
            mcPlayer.graphics.beginFill(0xcc0000,1);
            mcPlayer.graphics.drawRect(0,0,50,50);
            mcPlayer.graphics.endFill();
        }


        public function FlashTest() {
            // write as3 code here..            
            
            addChild(myText)
                        
            addChild(mcPlayer)
            drawPlayer();
            
            stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoved);

            
        }
        public function mouseMoved(e:MouseEvent):void{
                    mx = stage.mouseX - mcPlayer.width/2;
                    my = stage.mouseY - mcPlayer.height/2;
                    
                    myText.text = "X: " + String(mx) + "\n";
                    myText.appendText("Y: " + String(my) + "\n")
                    
                    mcPlayer.x = mx;
                    mcPlayer.y = my;
                 
        
        }

    }
}