位图作为按钮?
如何将位图设置为按钮,以便我可以在其上应用按钮模式和鼠标事件内容,而无需将位图添加到影片剪辑中?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不幸的是,Bitmap 对象不是从 InteractiveObject 类扩展的 - 也就是说,它们没有(也不能轻易获得)接收鼠标事件的能力。
正如 antpaw 和 Jeremy White 在之前的回答中指出的,接收鼠标事件的最简单的容器类是 Sprite 类。因此,如果您想让位图接收鼠标事件,并且不使用MovieClip,则可以使用Sprite:
事实上,我建议使用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:
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.
ButtonMode 是 Sprite 的一个属性,
影片剪辑的继承是这样的
buttonMode is a property of Sprite
inheritance of a movie clip goes like this