【问题标题】:ActionScript3 MouseEvent.CLICK not working with no errorsActionScript3 MouseEvent.CLICK 无法正常工作且没有错误
【发布时间】:2014-10-23 14:00:07
【问题描述】:

我想要实现的是,当牛仔被点击时,他消失了。我也用跟踪评论尝试过,点击牛仔时没有任何显示。

当我运行程序时,我没有收到任何错误。我不知道为什么。 这是我的代码

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

    /**
     * ...
     * @author Callum Singh
     */
    public class Main extends Sprite 
    {
        public var gun:crosshair;
        public var cowboy:enemy;

        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            gun = new crosshair();
            stage.addChild (gun);
            addEventListener(Event.ENTER_FRAME, moveCrosshair);

            cowboy = new enemy();
            cowboy.x = Math.random() * 600;
            cowboy.y = Math.random() * 400;
            stage.addChild (cowboy);
            addEventListener(MouseEvent.CLICK, handleShoot);
        }

        private function moveCrosshair(e:Event):void
        {
            gun.x = mouseX -120;
            gun.y = mouseY -115;

        }

        private function handleShoot(e:MouseEvent):void
        {
            if (e.target == cowboy)
                {
                    cowboy.visible = false;
                }
        }

    }

}

【问题讨论】:

    标签: actionscript-3 mouseevent


    【解决方案1】:

    确保将侦听器添加到 cowboy 对象,有时将 MouseEvent.CLICK 更改为 MouseEvent。MOUSE_DOWN 会有所帮助。

    cowboy.addEventListener(MouseEvent.MOUSE_DOWN, handleShoot);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多