PDA

View Full Version : [AS3] Multiple Button components on stage


pulse00
09-06-2008, 08:38 AM
Hi,

i'm trying to use Actionscript 3 Components, but all the demos in the documentation simply use a single button on the stage.

My Problem is that i need several buttons, which all have a different skin. Therefore if i only use on button component in the library and create multiple instances, all of them will use the same skin.

I then added multiple button components to the library, naming each one different, but i keep getting this warning:

**Warning** The linkage identifier 'fl.controls.Button' was already assigned to the symbol 'Button', and cannot be assigned to the symbol 'PlayButton', since linkage identifiers must be unique.

When changing the linkage identifier to something else than fl.controls.Button, the warning disappears but the Button keeps displaying all it's different skins at once, beneath each other.

Could anyone give me a hint how this is done properly in AS3 ?

thanks !

yogeshpuri
09-06-2008, 09:06 AM
Hello

Have a look at following example. This example creates 3 different style of buttons. You need to use textFormat in-case you need to change the button text style. However in-case you want to change the skin then use the SetStyle with library symbols


package
{
import fl.controls.Button;
import fl.controls.TextArea;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextFormat;

public class ButtonExample extends Sprite
{
private var b1:Button;
private var b2:Button;
private var b3:Button;
private var ta:TextArea;

public function ButtonExample() {
createTraceField();
setupButtons();
}
private function createTraceField():void {
ta = new TextArea();
ta.setSize(200, 300);
ta.move(200, 10);
addChild(ta);
}
private function setupButtons():void {
b1 = new Button();
b2 = new Button();
b3 = new Button();

b1.width = 160;
b2.width = 160;
b3.width = 160;

b1.move(10,10);
b2.move(10,40);
b3.move(10,70);

b1.label = "Default Button";
b2.label = "Custom Styled Button";
b3.label = "Toggle Button";

b2.setStyle("textFormat", new TextFormat("Georgia"));

b3.toggle = true;

b1.addEventListener(MouseEvent.CLICK, buttonClick);
b2.addEventListener(MouseEvent.CLICK, buttonClick);
b3.addEventListener(MouseEvent.CLICK, buttonClick);

addChild(b1);
addChild(b2);
addChild(b3);
}
private function buttonClick(e:MouseEvent) {
var button:Button = e.target as Button;
ta.appendText(button.label + "\n");
}
}


For more details refer following two links

http://board.flashkit.com/board/showthread.php?t=737473
http://www.gskinner.com/blog/archives/2007/06/stylecollection.html

pulse00
09-06-2008, 09:29 AM
thanks a lot, that did the trick.

yogeshpuri
09-06-2008, 09:31 AM
You are welcome :D