• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Draw Multiple Buttons

Community Beginner ,
Aug 31, 2012 Aug 31, 2012

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 to some of them and I get an error when I do that is ReferenceError: Error #1069: Property 1 not found on flash.display.Sprite and there is no default value.) thanks.

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.y = 275;

                    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);

                    }

          }

}

TOPICS
ActionScript

Views

580

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 31, 2012 Aug 31, 2012

remove:

   button.graphics.clear();

and make sure your stage is large enough (~760x350) to see your buttons.

Votes

Translate

Translate
Community Expert ,
Aug 31, 2012 Aug 31, 2012

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

Yes. I see trace of 1, 2, and 3

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

remove:

   button.graphics.clear();

and make sure your stage is large enough (~760x350) to see your buttons.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 31, 2012 Aug 31, 2012

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2012 Aug 31, 2012

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines