Using MouseEvent in Conjunction with the Mouse : MouseEvent : Development Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Development » MouseEvent »

 

Using MouseEvent in Conjunction with the Mouse


 
package
{
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.ui.Mouse;
    public class Main extends Sprite
    {
        private var circleMouse:Sprite = new Sprite();
        private var squareMouse:Sprite = new Sprite();
        private var currentMouse:Sprite = new Sprite();

        private var useSquareField:Sprite = new Sprite();
        private var useCircleField:Sprite = new Sprite();

        public function Main()
        {
            useSquareField.graphics.beginFill(0xFFFFFF1);
            useSquareField.graphics.drawRect(00100100);
            useSquareField.graphics.endFill();
            useSquareField.name = "square";
            useSquareField.x = 200;

            useCircleField.graphics.beginFill(0xFFFFFF1);
            useCircleField.graphics.drawRect(00100100);
            useCircleField.name = "circle";
            useCircleField.graphics.endFill();
            addChild(useCircleField);
            addChild(useSquareField);

            useCircleField.addEventListener(MouseEvent.ROLL_OVER, useCircle);
            useSquareField.addEventListener(MouseEvent.ROLL_OVER, useSquare);
            useCircleField.addEventListener(MouseEvent.ROLL_OUT, showMouse);
            useSquareField.addEventListener(MouseEvent.ROLL_OUT, showMouse);

            circleMouse.graphics.beginFill(0x00ff001);
            circleMouse.graphics.drawCircle(005);
            circleMouse.graphics.endFill();
            currentMouse = new Sprite();

            squareMouse.graphics.beginFill(0xff00001);
            squareMouse.graphics.drawRect(001010);
            squareMouse.graphics.endFill();
            this.stage.addEventListener(MouseEvent.MOUSE_MOVE, moveNewMouse);
        }

        private function moveNewMouse(mouseEvent:MouseEvent):void

        {
            currentMouse.x = mouseEvent.stageX + 5;
            currentMouse.y = mouseEvent.stageY + 5;
            mouseEvent.updateAfterEvent();
        }

        private function useSquare(mouseEvent:MouseEvent):void
        {
            Mouse.hide();
            addChild(squareMouse);
            currentMouse = squareMouse;
        }

        private function useCircle(mouseEvent:MouseEvent):void
        {
            Mouse.hide();
            addChild(circleMouse);
            currentMouse = circleMouse;
        }

        private function showMouse(mouseEvent:MouseEvent):void
        {
            if((mouseEvent.target as Sprite== useSquareField)
            {
                removeChild(squareMouse);
            }
            else {
                removeChild(circleMouse);
            }
            currentMouse = new Sprite();
            Mouse.show();
        }
    }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Development
» MouseEvent