这里是前提:
我有 10 个按钮,每个按钮都有正常状态图像 (buttonX.png) 和鼠标悬停状态 (buttonXglow.png)。这些按钮是在 Flash 中手动创建的,但在我的 as3 主类中引用。
我需要向按钮添加不同的状态。
我想要执行以下操作:
- 将按钮标记为选定状态,例如始终使用 (buttonXglow.png) 显示它。
-
能够禁用按钮(我正在使用 mouseEnabled = false; 此时会关闭其行为,但我也想将外观更改为 (buttonXout.png) 图像)。
-
在 AS3 中似乎相当复杂,我尝试嵌入 (buttonXglow.png) 图像,并将其作为成员变量放置在我的主类中,但它似乎对我不起作用。
[嵌入(source='button1out.png')]
公共静态变量Button1Out:类;
另外,如果我让它工作,我不确定如何用位图实际替换按钮外观。我想我应该更换按钮的 upState 。
提前致谢!
Here is the premise:
I have 10 buttons each with on normal state image (buttonX.png) and a mouseover state (buttonXglow.png). The buttons are created manually in flash, but referenced in my as3 main class.
I need to add different states to the buttons.
I want do the following:
- mark on of the buttons as selected, e.g. show it with the (buttonXglow.png) all the time.
-
be able to disable the buttons (I'm using mouseEnabled = false; at the moment which turns its behavior off, but I also want to change the appearance to a (buttonXout.png) image).
-
seems fairly complicated in AS3, I've tried to embed the (buttonXglow.png) images with the following which I placed as member variables in my main class, but it doesn't seem work for me.
[Embed(source='button1out.png')]
public static var Button1Out:Class;
Also I'm not sure how to actually replace the buttons apperance with the bitmap if I get it to work. I was thinking that I should replace the upState of the button.
Thanks in advance!
发布评论
评论(2)
似乎是上面的 [Embed(...)] 语法属于 FlashDeveloper 的答案,
对于我正在使用的 Flash CS3,该选项是将图像手动导入到库中
并设置为每个图像创建一个类(有点耗时,但它有效)。
编辑:请注意,我遇到了“2022 类 %1 必须从 DisplayObject 继承才能链接到符号。”的问题。这似乎是 Flash CS3 中的一个错误,由于某种原因,链接停止工作。我通过从库中删除图像并再次导入它们来解决此问题。
使用“位图属性”窗口中的“链接”选项来设置“导出为 ActionScript”。
设置类名,基类将设置为 flash.display.BitmapData。
在您的代码中,您可以照常使用该类,例如:
var image:Bitmapdata=new Button1outClass(23, 23); // 请注意,我必须在构造函数中设置宽度和高度。
我使用以下代码生成带有位图的 Sprite:
这引导我们
通过指向即可轻松解决
button.upState=button.overState;
来解决(问题是我需要保存 upState 以便可以恢复它)
很简单:
button.upState=button1Out:
这里恢复也是一个问题,但由于我只是禁用按钮,再也不会启用它们,所以我很高兴去这里)
Seems like the answer here that the [Embed(...)] syntax above belongs to FlashDeveloper,
for Flash CS3 which I'm using the option is to manually import the images in to a library
and set up so a class is created for each image (a bit time consuming but it worked).
Edit: Note that I had problems with "2022 Class %1 must inherit from DisplayObject to link to a symbol.". This seems to be a bug in Flash CS3 that for some reason the Linkage stopped working. I solve this by deleting the images from the library and import them again.
Use the Linkage option in the "Bitmap property" window to set Export for ActionScript.
Set you class name, the base class will be set to flash.display.BitmapData.
In your code you can used the class as usual, e.g.:
var image:Bitmapdata=new Button1outClass(23, 23); // Notice that I had to set the width and height inte the constructor.
I used the following code to generate a Sprite with the bitmap:
Which leads us in on
Is easily solved by pointing
button.upState=button.overState;
(problem is that I need save the upState so I can restore it)
is as easy as:
button.upState=button1Out:
(also here restore is an issue but since I'm only goning to disable buttons never enable them again I'm good to go here)
好吧,我想说 ActionScript 是唯一的方法......如果你幸运的话,你会找到一个组件,但我想,你必须自己做......
无论如何......让位图出现,您需要执行类似
myButton.upState = new Button1Out();
的操作...希望能回答您的问题...:)well, i'd say ActionScript is the only way to go ... if you're lucky you'll find a component, but i guess, you'll have to do it on your own ...
anyway ... to make the bitmap appear, you'll need to do something like
myButton.upState = new Button1Out();
... hope that answers your question ... :)