位图作为按钮?

发布于 2024-08-28 13:28:05 字数 301 浏览 2 评论 0原文

如何将位图设置为按钮,以便我可以在其上应用按钮模式和鼠标事件内容,而无需将位图添加到影片剪辑中?

var bmpFull=new Bitmap(event.currentTarget.content.bitmapData);
        bmpFull.smoothing=true;
        bmpFull.name="photo";
        bmpFull.alpha=0;

        //fullMC.buttonMode=true;
        fullMC.addChild(bmpFull);

How to set a bitmap as a button so that i can apply button mode and mouse-event stuff on it, without adding the bitmap to a Movie Clip?

var bmpFull=new Bitmap(event.currentTarget.content.bitmapData);
        bmpFull.smoothing=true;
        bmpFull.name="photo";
        bmpFull.alpha=0;

        //fullMC.buttonMode=true;
        fullMC.addChild(bmpFull);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟月 2024-09-04 13:28:05

不幸的是,Bitmap 对象不是从 InteractiveObject 类扩展的 - 也就是说,它们没有(也不能轻易获得)接收鼠标事件的能力。

正如 antpaw 和 Jeremy White 在之前的回答中指出的,接收鼠标事件的最简单的容器类是 Sprite 类。因此,如果您想让位图接收鼠标事件,并且使用MovieClip,则可以使用Sprite:

var bmpFull:Bitmap = new Bitmap(event.currentTarget.content.bitmapData);
bmpFull.smoothing = true;
bmpFull.name = "photo";
bmpFull.alpha = 0;

var bmpContainer:Sprite = new Sprite(); // can receive mouse events, for example:
bmpContainer.addEventListener(MouseEvent.CLICK, clickHandler);
bmpContainer.buttonMode = true; // this just makes it show the hand cursor, and is not necessary for the mouse events to work
bmpContainer.addChild(bmpFull);

事实上,我建议使用Sprite,因为它们是比MovieClip更简单的对象因此不需要那么多的内存。

现在,如果您想让 Bitmap 调度鼠标事件而不使用任何类型的容器剪辑,您可能需要编写自己的 Bitmap 类扩展,该扩展拥有自己的事件管理器。那会复杂得多。我强烈建议仅使用 Sprite 作为容器。

Unfortunately, Bitmap objects do not extend from the InteractiveObject class - that is, they don't have (and cannot easily get) the ability to receive mouse events.

As pointed out by antpaw and Jeremy White in the previous answer, the simplest container class that does receive mouse events is the Sprite class. Therefore, if you wanted to have a Bitmap receive mouse events, and not use a MovieClip, you could use a Sprite:

var bmpFull:Bitmap = new Bitmap(event.currentTarget.content.bitmapData);
bmpFull.smoothing = true;
bmpFull.name = "photo";
bmpFull.alpha = 0;

var bmpContainer:Sprite = new Sprite(); // can receive mouse events, for example:
bmpContainer.addEventListener(MouseEvent.CLICK, clickHandler);
bmpContainer.buttonMode = true; // this just makes it show the hand cursor, and is not necessary for the mouse events to work
bmpContainer.addChild(bmpFull);

In fact, I would recommend using a Sprite, as they're simpler objects than MovieClips and thus do not require as much memory.

Now, if you wanted to make a Bitmap dispatch mouse events without using any sort of container clip, you'd probably need to write your own extension of the Bitmap class that had it's own event manager. That would be far, far more complicated. I highly recommend just using a Sprite as a container.

梦里°也失望 2024-09-04 13:28:05

ButtonMode 是 Sprite 的一个属性,

影片剪辑的继承是这样的

MovieClip >> Sprite >> DisplayObjectContainer >> InteractiveObject >> DisplayObject >> EventDispatcher >> Object

                                                            Bitmap >> DisplayObject >> EventDispatcher >> Object

buttonMode is a property of Sprite

inheritance of a movie clip goes like this

MovieClip >> Sprite >> DisplayObjectContainer >> InteractiveObject >> DisplayObject >> EventDispatcher >> Object

                                                            Bitmap >> DisplayObject >> EventDispatcher >> Object
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文