【问题标题】:tileList cells respond to mouse events in as3tileList 单元格响应 as3 中的鼠标事件
【发布时间】:2011-05-09 23:06:42
【问题描述】:

我正在制作一个 Flash 游戏(它基本上是同一个游戏的一个版本),并且我使用了 tileList 用于填充有 movieClip 棋子的棋盘。我希望这些作品能够响应 mouseOvermouseOutmouseClick 事件。

通过查看其他问题/答案,我知道我需要一个自定义 imageCell。这就是要走的路吗。我希望我可以通过将操作放入movieClips 本身如下来获得我想要的响应,但这似乎不起作用。 (顺便说一句,我是社区的新手,但已经从 Google 搜索中多次来到这里……感谢您的帮助,我已经从你们这些好人那里得到了帮助。干杯。)

this.addEventListener(MouseEvent.MOUSE_OVER, OverHandler);
this.addEventListener(MouseEvent.MOUSE_OUT, OutHandler);
this.addEventListener(MouseEvent.CLICK, ClickHandler);

this.stop();

function OverHandler(event:MouseEvent):void
{
event.target.play();
}

function OutHandler(event:MouseEvent):void
{
event.target.stop();
}

function ClickHandler(event:MouseEvent):void
{
    event.target.play();
}

【问题讨论】:

    标签: flash actionscript-3 flash-cs5


    【解决方案1】:

    我可能会为你在游戏中的所有片段设置一个基类,这些片段在那里有事件并准备好了。就像这样:

    package
    {
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
    
        public class Piece extends MovieClip
        {
            /**
             * Constructor
             */
            public function Piece()
            {
                addEventListener(MouseEvent.CLICK, _click);
                addEventListener(MouseEvent.ROLL_OVER, _rollOver);
                addEventListener(MouseEvent.ROLL_OUT, _rollOut);
            }
    
            /**
             * Called on MouseEvent.CLICK
             */
            protected function _click(e:MouseEvent):void
            {
                trace(this + " was clicked");
            }
    
            /**
             * Called on MouseEvent.ROLL_OVER
             */
            protected function _rollOver(e:MouseEvent):void
            {
                trace(this + " was rolled over");
            }
    
            /**
             * Called on MouseEvent.ROLL_OUT
             */
            protected function _rollOut(e:MouseEvent):void
            {
                trace(this + " was rolled off");
            }
    
            /**
             * Destroys this
             */
            public function destroy():void
            {
                // listeners
                addEventListener(MouseEvent.CLICK, _click);
                addEventListener(MouseEvent.ROLL_OVER, _rollOver);
                addEventListener(MouseEvent.ROLL_OUT, _rollOut);
    
                // from DisplayList
                if(parent) parent.removeChild(this);
            }
        }
    }
    

    如果您需要 click、roll_over 或 roll_out 在某些部分上做任何独特的事情,只需扩展并执行以下操作:

    package
    {
        import flash.events.MouseEvent;
    
        public class MyPiece extends Piece
        {
            override protected function _click(e:MouseEvent):void
            {
                trace("mypiece was clicked");
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-10
      相关资源
      最近更新 更多