如何禁用 SimpleButton 包括更改其外观

发布于 2024-08-12 07:52:17 字数 581 浏览 6 评论 0 原文

这里是前提:

我有 10 个按钮,每个按钮都有正常状态图像 (buttonX.png) 和鼠标悬停状态 (buttonXglow.png)。这些按钮是在 Flash 中手动创建的,但在我的 as3 主类中引用。 我需要向按钮添加不同的状态。

我想要执行以下操作:

  1. 将按钮标记为选定状态,例如始终使用 (buttonXglow.png) 显示它。
  2. 能够禁用按钮(我正在使用 mouseEnabled = false; 此时会关闭其行为,但我也想将外观更改为 (buttonXout.png) 图像)。

  3. 在 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:

  1. mark on of the buttons as selected, e.g. show it with the (buttonXglow.png) all the time.
  2. 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).

  3. 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!

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

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

发布评论

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

评论(2

十秒萌定你 2024-08-19 07:52:17
  • 在 AS3 中似乎相当复杂,我尝试嵌入
    (buttonXglow.png) 图像
    之后我成为会员
    我的主类中的变量,但它
    似乎不适合我。

    [嵌入(source='button1out.png')]
    公共静态变量Button1Out:Class;

  • (这在 flash cs3 中不起作用)

    似乎是上面的 [Embed(...)] 语法属于 FlashDeveloper 的答案,
    对于我正在使用的 Flash CS3,该选项是将图像手动导入到库中
    并设置为每个图像创建一个类(有点耗时,但它有效)。

    编辑:请注意,我遇到了“2022 类 %1 必须从 DisplayObject 继承才能链接到符号。”的问题。这似乎是 Flash CS3 中的一个错误,由于某种原因,链接停止工作。我通过从库中删除图像并再次导入它们来解决此问题。

    使用“位图属性”窗口中的“链接”选项来设置“导出为 ActionScript”。
    设置类名,基类将设置为 flash.display.BitmapData。

    在您的代码中,您可以照常使用该类,例如:

    var image:Bitmapdata=new Button1outClass(23, 23); // 请注意,我必须在构造函数中设置宽度和高度。

    我使用以下代码生成带有位图的 Sprite:

    button1Out=new Sprite();
    button1Out.addChild(new Bitmap(new Button1outClass(23, 23)));   
    

    这引导我们

    1. 将按钮标记为已选择,例如用
      (buttonXglow.png) 始终如此。
    2. 能够禁用按钮(我正在使用 mouseEnabled = false; 在
      关闭其行为的时刻,
      但我也想改变
      (buttonXout.png) 的外观
      图片)。
    1. 通过指向即可轻松解决

      button.upState=button.overState;

    来解决(问题是我需要保存 upState 以便可以恢复它)

    1. 很简单:

      button.upState=button1Out:

    这里恢复也是一个问题,但由于我只是禁用按钮,再也不会启用它们,所以我很高兴去这里)

    1. 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;

    (this doesn't work in flash cs3)

    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:

    button1Out=new Sprite();
    button1Out.addChild(new Bitmap(new Button1outClass(23, 23)));   
    

    Which leads us in on

    1. Mark on of the buttons as selected, e.g. show it with the
      (buttonXglow.png) all the time.
    2. 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).
    1. Is easily solved by pointing

      button.upState=button.overState;

    (problem is that I need save the upState so I can restore it)

    1. 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)

    旧城烟雨 2024-08-19 07:52:17

    好吧,我想说 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 ... :)

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