DoomOfTheLiving
11-04-2008, 02:07 AM
I've got a working button right now, with 3 Sprites for the up, over/hitTest, and down states. I'm having trouble figuring out how to add text to all three states, though. I have a dynamically created text box that reads "Click Me" that I want to add as a child of all three Sprites. Here's the code I'm using:
//"Click Me" Button Text Formatting
var buttonTextFormat:TextFormat = new TextFormat();
buttonTextFormat.font = "Arial";
buttonTextFormat.size = 14;
//"Click Me" Button Text
var buttonText:TextField = new TextField();
buttonText.text = "Click Me";
buttonText.selectable = false;
buttonText.setTextFormat(buttonTextFormat);
buttonText.autoSize = TextFieldAutoSize.LEFT;
//"Click Me" Button Up State
var buttonUpState:Sprite = new Sprite;
buttonUpState.graphics.lineStyle(2, 0x000000);
buttonUpState.graphics.beginFill(0x00FF00);
buttonUpState.graphics.drawRect(0,0,100,40);
buttonUpState.graphics.endFill();
buttonUpState.addChild(buttonText);
buttonText.x = (buttonUpState.width - buttonText.width) / 2;
buttonText.y = (buttonUpState.height - buttonText.height) / 2;
//"Click Me" Button Over and hitTest States
var buttonOverState:Sprite = new Sprite;
buttonOverState.graphics.lineStyle(2, 0x000000);
buttonOverState.graphics.beginFill(0x00FF00);
buttonOverState.graphics.drawRect(0,0,100,40);
buttonOverState.graphics.endFill();
buttonOverState.alpha = 0.75;
//"Click Me" Button Down State
var buttonDownState:Sprite = new Sprite;
buttonDownState.graphics.lineStyle(2, 0x000000);
buttonDownState.graphics.beginFill(0x00FF00);
buttonDownState.graphics.drawRect(2,2,100,40);
buttonDownState.graphics.endFill();
//Creates "Click Me" Button
var clipButton:SimpleButton = new SimpleButton(buttonUpState, buttonOverState, buttonDownState, buttonOverState);
clipButton.x = (stage.stageWidth / 2) - (clipButton.width / 2);
clipButton.y = 300;
stage.addChild(clipButton);
Right now I only have the text box nested inside of the buttonUp Sprite. How can I nest that text box inside of all three Sprites?
//"Click Me" Button Text Formatting
var buttonTextFormat:TextFormat = new TextFormat();
buttonTextFormat.font = "Arial";
buttonTextFormat.size = 14;
//"Click Me" Button Text
var buttonText:TextField = new TextField();
buttonText.text = "Click Me";
buttonText.selectable = false;
buttonText.setTextFormat(buttonTextFormat);
buttonText.autoSize = TextFieldAutoSize.LEFT;
//"Click Me" Button Up State
var buttonUpState:Sprite = new Sprite;
buttonUpState.graphics.lineStyle(2, 0x000000);
buttonUpState.graphics.beginFill(0x00FF00);
buttonUpState.graphics.drawRect(0,0,100,40);
buttonUpState.graphics.endFill();
buttonUpState.addChild(buttonText);
buttonText.x = (buttonUpState.width - buttonText.width) / 2;
buttonText.y = (buttonUpState.height - buttonText.height) / 2;
//"Click Me" Button Over and hitTest States
var buttonOverState:Sprite = new Sprite;
buttonOverState.graphics.lineStyle(2, 0x000000);
buttonOverState.graphics.beginFill(0x00FF00);
buttonOverState.graphics.drawRect(0,0,100,40);
buttonOverState.graphics.endFill();
buttonOverState.alpha = 0.75;
//"Click Me" Button Down State
var buttonDownState:Sprite = new Sprite;
buttonDownState.graphics.lineStyle(2, 0x000000);
buttonDownState.graphics.beginFill(0x00FF00);
buttonDownState.graphics.drawRect(2,2,100,40);
buttonDownState.graphics.endFill();
//Creates "Click Me" Button
var clipButton:SimpleButton = new SimpleButton(buttonUpState, buttonOverState, buttonDownState, buttonOverState);
clipButton.x = (stage.stageWidth / 2) - (clipButton.width / 2);
clipButton.y = 300;
stage.addChild(clipButton);
Right now I only have the text box nested inside of the buttonUp Sprite. How can I nest that text box inside of all three Sprites?