views:

336

answers:

2

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!

A: 

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

back2dos
A: 
  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)

Johan Carlsson