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;
}
}
}
Copy link to clipboard
Copied
create and add a textfield to your ball and assign its text property.
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;
}
Copy link to clipboard
Copied
the ball won't have a text property, textBall has the text property. and your textfield will move with your ball.