actionscript-3 - 位图作为按钮?

标签 actionscript-3 button bitmap

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

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

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

最佳答案

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

正如 antpaw 和 Jeremy White 在上一个答案中所指出的,接收鼠标事件的最简单的容器类是 Sprite 类。因此,如果您想让 Bitmap 接收鼠标事件,而使用 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,因为它们是比 MovieClips 更简单的对象,因此不需要太多内存。

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

关于actionscript-3 - 位图作为按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2614440/

相关文章:

flash - 如何为您的网络应用程序创建漂亮的截屏视频?

c# - 减小位图图像的物理尺寸?

.net - 如何在 .net 中以 4-2-2 格式保存高质量的 jpeg?

c# - 位图.Save "Generic Error"

javascript - 带有 jQ​​uery 的按钮监听器不起作用

button - 一键多个弹出窗口

javascript - AS3/JavaScript if 语句逗号而不是 & &

actionscript-3 - 声音缺少Flash AS3

flash - 如何在 Actionscript 3.0 中使用静态函数?

jQuery 按钮点击问题