加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash – BitMap Eventlistener不工作

发布时间:2020-12-15 07:25:36 所属栏目:百科 来源:网络整理
导读:我正在尝试向我的BitMap添加一个事件监听器. Tile扩展了gameProps,扩展了BitMap.我尝试使用addEventListener.那不起作用.但是Adobe文档说Bitmap有一个addEventListener对象. package { import flash.display.BitmapData; import flash.events.*; import flas
我正在尝试向我的BitMap添加一个事件监听器. Tile扩展了gameProps,扩展了BitMap.我尝试使用addEventListener.那不起作用.但是Adobe文档说Bitmap有一个addEventListener对象.

package {
            import flash.display.BitmapData;
            import flash.events.*;
            import flash.events.MouseEvent;
            import flash.geom.Rectangle;
            import flash.geom.Point;

            public class Tile extends gameProps {

                public var tileNum:Number = 0;


                public function Tile(tileNumber:Number):void
                {
                    tileNum = tileNumber;           
                    addEventListener(MouseEvent.MOUSE_OVER,respond);
                }


                public function respond(e:MouseEvent):void
                {   trace("HELLO");             
                }

            }   
        }

解决方法

Bitmap类扩展了DisplayObject而不是InteractiveObject,因此无法接收鼠标事件.尝试将位图对象包装在Sprite子类中.像这样的东西(伪代码):

public class Image extends Sprite
{
     var bitmap:Bitmap;

     public function Image()
     {
         bitmap = new Bitmap();
         addChild( bitmap );
     }
}

InteractiveObject文档:http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/InteractiveObject.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读