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

Creating a ball in AS3 with its label

New Here ,
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

Hi

The ball created below is drawn as a red ball

I want also to write its name "red" and place it on the ball whatever the ball position on the stage is

Can you help?

below i listed the code of class Ball and class DrawBall

package {
    import flash.display.Sprite;
   
    public class Ball extends Sprite {
        private var radius:Number;
        private var color:uint;
       
        public function Ball(radius:Number=40, color:uint=0xff0000) {
            this.radius = radius;
            this.color = color;
            init();
        }
        public function init():void {
            graphics.beginFill(color);
            graphics.drawCircle(0, 0, radius);
            graphics.endFill();
        }
    }
}

package {
    import flash.display.Sprite;
       
    public class DrawBall extends Sprite {
        private var ball:Ball;
       
        public function DrawBall()    {
            init();
        }
        private function init():void {
            ball = new Ball();
            addChild(ball);
            ball.x = stage.stageWidth/2;
            ball.y =stage.stageHeight/2;
        }       
    }
}

TOPICS
ActionScript

Views

742

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 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

create and add a textfield to your ball and assign its text property.

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
New Here ,
Aug 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

forget to mention that the text needs to be inside within the ball boundaries, so it resizes as necessary

bty did not find a property text for the ball (sprite)

mimi

private function init():void {
            ball = new Ball();
            textBall = new TextField;
            addChild(ball);
            ball.addChild(textBall)
            ball.x = stage.stageWidth/2;
            ball.y = stage.stageHeight/2;

}

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 20, 2009 Aug 20, 2009

Copy link to clipboard

Copied

LATEST

the ball won't have a text property, textBall has the text property.  and your textfield will move with your ball.

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