Copy link to clipboard
Copied
Is it possible to use a For loop to create 3 buttons on the stage and add text to them? This is what I have been working with but it just creates one button and i am not sure why. Can anyone help? ( I have added button
CODE EX.
function drawButtons():void
{
var textLabel:TextField = new TextField();
for (var j:Number = 1; j<4; j++)
{
button.graphics.clear();
button = new Sprite();
button.graphics.beginFill(0x000000);
// purple color;
button.graphics.drawRoundRect(0, 0, 80, 25, 10, 10);
// x, y, width, height, ellipseW, ellipseH;
button.graphics.endFill();
button.x = 725;
//button
this.addChild(button);
button.buttonMode = true;
button.useHandCursor = true;
button.mouseChildren = false;
textLabel.textColor = 0xFFFFFF;
textLabel.x = 10;
textLabel.selectable = false;
textLabel.defaultTextFormat = textFormat;
this.button.addChild(textLabel);
if (j == 1)
{
trace(j);
button.y = 275;
textLabel.text = "A";
textLabel.y = 5;
//Add Answer Button Listner
button.addEventListener(MouseEvent.MOUSE_DOWN, answerA_MouseDown);
}
if (j == 2)
{
trace(j);
button.y = 300;
textLabel.text = "B";
textLabel.y = 5;
//Add Answer Button Listner
button.addEventListener(MouseEvent.MOUSE_DOWN, answerB_MouseDown);
}
if (j == 3)
{
trace(j);
button.y = 325;
textLabel.text = "C";
textLabel.y = 5;
//Add Answer Button Listner
button.addEventListener(MouseEvent.MOUSE_DOWN, answerC_MouseDown);
}
}
}
remove:
button.graphics.clear();
and make sure your stage is large enough (~760x350) to see your buttons.
Copy link to clipboard
Copied
remove that clear(), make sure you're calling drawButtons and make sure your stage is large enough (esp width) to see those buttons.
Copy link to clipboard
Copied
Yes. I see trace of 1, 2, and 3
Copy link to clipboard
Copied
remove:
button.graphics.clear();
and make sure your stage is large enough (~760x350) to see your buttons.
Copy link to clipboard
Copied
ok wow that is awesome but I only see the text for "C" in the box. The other two are empty?
Copy link to clipboard
Copied
use:
CODE EX.
function drawButtons():void
{
// var textLabel:TextField = new TextField();
for (var j:Number = 1; j<4; j++)
{
var textLabel:TextField = new TextField(); |
p.s. please mark helpful/correct responses.