PDA

View Full Version : [AS3] setStyle not working for disabled button component


zumajoe
01-14-2010, 07:19 PM
Hello,

It seems that the only way to make an AS3 button component change it's "Skin" is to removeChild and create another button component instance using the "setStyle - whateverVariableICreated". I would rather keep the same button as to not clutter things with creating and removing them.

I would assume this would be the same for Radio Buttons...

Anyone have a clue?

http://www.adobe.com/devnet/flash/quickstart/button_component_as3

My code, showing that once clicked- once the .enabled = false.. it will not change the skin. However, if you comment out the .enabled = false or set it to true, it works.

import flash.display.MovieClip;
import flash.events.MouseEvent;
import fl.managers.*;
import fl.controls.Button;
import fl.controls.ButtonLabelPlacement;


// Create a new TextFormat object which will be used when the button is enabled.
var enabledTextFormat:TextFormat = new TextFormat();
enabledTextFormat.font = "Arial";
enabledTextFormat.size = 12;


// Create a new TextFormat object which will be used when the button is disabled.
var disabledTextFormat:TextFormat = new TextFormat();
disabledTextFormat.color = 0xFF0000;
disabledTextFormat.font = "Arial";
disabledTextFormat.size = 15;


// Create Flash Component button
var myButton:Button = new Button()
myButton.setSize(120, 22);
myButton.move(90, 0);
addChild(myButton);
myButton.label="Start Animation";
myButton.labelPlacement = ButtonLabelPlacement.LEFT;
myButton.setStyle("textFormat", enabledTextFormat);
myButton.setSize(120, 22);
myButton.move(90, 0);




/* Handler function for the enabledButton and disabledButton button instances. This
function updates the target button's label property when the button is clicked. However refuses to "skin" the button per thedisabledTextFormat variable */
function clickHandler(event:MouseEvent):void {
var btn:Button = event.currentTarget as Button;
btn.label = "Ouch!";
btn.enabled = false;
btn.emphasized = btn.enabled;
//myButton.enabled = false;
myButton.setStyle("textFormat", disabledTextFormat);
}

myButton.addEventListener(MouseEvent.CLICK, clickHandler);