flash跟随鼠标样式

 

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

    
    public class FollowMouse extends Sprite {
        
        private var _icon : Shape; //鼠标样式
        private var box : Sprite; //被点击的对像
        
        
        public function FollowMouse() {
            //鼠标样式不能为可接收事件对像,否则无法点击其它对像
            _icon = new Shape();
            _icon.graphics.beginFill(0xff0000);
            _icon.graphics.drawCircle(0, 0, 20);
            _icon.graphics.endFill();
            _icon.name = "mouse icon";
            
            this.stage.addChild(_icon);
            _icon.x = stage.stageWidth / 2 - _icon.width / 2;
            _icon.y = stage.stageHeight / 2 - _icon.height / 2;
            Mouse.hide();
            
            stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
            
            box = new Sprite();
            box.graphics.beginFill(0x000000);
            box.graphics.drawRect(0, 0, 100, 100);
            box.graphics.endFill();
            addChild(box);
            box.addEventListener(MouseEvent.CLICK, boxClick);
            //_icon.addEventListener(MouseEvent.CLICK, iconClick);
            
        }
        
        private function iconClick(e : MouseEvent) : void {
            trace(".....................");
        }
        
        private function boxClick(e : MouseEvent) : void {
            box.visible = false;
        }
        
        private function onMove(e : MouseEvent) : void {
            _icon.x = mouseX;
            _icon.y = mouseY;
        }
    }
}

 

 

posted @ 2012-10-17 11:40  playerlife  阅读(451)  评论(0编辑  收藏  举报