问题描述
朋友
我是AS3的新手,请原谅.我正在尝试仅使用AS3将图像用作按钮(PNG/GIF图像作为按钮(简单,切换和多状态)-鼠标悬停,正常和按下时图像更改).我试图搜寻.我所要做的就是设置按钮的图标.如果您可以共享代码段或指针,那就太好了.
I am new to AS3 so pardon me. I am trying to use images as buttons (PNG/GIF images as buttons(simple, toggled and multi-state) - Image change on mouse over, normal and pressed) using AS3 only. I tried to search. All I got is to setting icon of a Button. It would be really great if you can share the code snippet or pointers.
非常感谢.
推荐答案
有些方法可以将图像转换为Movieclip.您可以使用[Embed]标签将图像嵌入SWF中....或者,更好的方法是,可以使用Loader类加载图像.
There are ways to do this without converting an image to a Movieclip. You can either embed your images inside your SWF using the [Embed] tag....or, a better way, you can load them using the Loader class.
您将像这样加载图像:
var myloader:Loader = new Loader();
myloader.load(new URLRequest("myImage"));
...,然后在加载完成后使用如下方式获取其BitmapData(使用事件侦听器捕获):
...and then you would get its BitmapData like this after the loading completes (use an event listener to catch this):
var myBitmapData:BitmapData = Bitmap(myloader.content).bitmapData;
BitmapData对象需要一个Bitmap容器才能将其放置在舞台上,因此您需要使用BitmapData作为输入声明一个Bitmap实例.
A BitmapData object needs a Bitmap container in order for it to be placed on the stage, so you'll need to declare a Bitmap instance using the BitmapData as input.
var Bitmap:Bitmap = new Bitmap(myBitmapData);
由于可以将Bitmap添加到舞台上,因此您很高兴.您可以将其用作按钮类的一部分.还有更多位图信息此处位于8bitrocket.
Since that Bitmap can be added to the stage, you're good to go. You can use that as part of your button class. There's some more Bitmap information here at 8bitrocket.
对于那些不使用Flash CS 5或其他动画片剪辑创作者的人来说,这是一种不错的选择.我正在使用这种技术在FlashDevelop中制作游戏,并且效果很好.
This is a nice way of doing it for those of us who don't use Flash CS 5, or any other movieclip creators. I'm making a game in FlashDevelop using this technique and it works well.
希望这有助于仅动作脚本"方法.祝你好运.
Hope this helps as an "actionscript only" method. Good luck.
这篇关于使用AS3将PNG/GIF图像用作按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!