i have a loaded swf fil, in this file, a movieclip named ball on it, this movieclip move when i press a button, at the moment, i want to add a text on this movieclip, as movieclip moving, text move with it as if they are the same object
views:
804answers:
2
A:
Umm. I'm not sure what exactly you wish to do, but If I understand you correctly, there are a few ways of implementing this.
OPTION 1:
button.addEventListener(MouseEvent.CLICK, followFunc);
private function followFunc(event:MouseEvent):void {
removeChild(text);
movieClip.addChild(text);
}
OPTION 2:
button.addEventListener(MouseEvent.CLICK, followFunc);
private function followFunc(event:MouseEvent):void {
stage.addEventListener(Event.ENTER_FRAME, updateFunc);
}
private function updateFunc(event:Event):void {
text.x = movieClip.x; //possibly + or - some offset
text.y = movieClip.y;
}
PiPeep
2009-07-09 02:50:18
By the way, why are you using MovieClips? Sprites are faster if you don't need the frames.
PiPeep
2009-07-09 02:51:09
thanks, my english is very poor,so i can not express myself very collectly. let me try to explain it again. i want to attach a text to a ball run as a movieclip when i click a button,when the button clicked, the ball move from bottom to top, the text will right on the ball and move with it.
2009-07-09 05:50:28
i use the option 1 you point out,but the text did not appear on the ball but in other place, when the ball move, the text still there
2009-07-09 05:51:59
i did not use sprite because my ball is on a time frame
2009-07-09 05:53:39
A:
Since the ball is on a timeline, the simplest approach may be to put a textfield in the same MovieClip that the ball is in. Something like the ball asset is on Layer 1, and the textfield is on Layer 2.
Position the textfield as you want it to be, on the ball.
You would need to name the textfield -- something like 'ballTextField', maybe.
Name your ball MovieClip, when you add it to the stage (either in the Flash authoring environment, or programatically). Call it something like 'ball'.
Then:
button.addEventListener(MouseEvent.CLICK, buttonClickListener);
private function buttonClickListener(e:MouseEvent):void
{
ball.ballTextField.text = "Hi. This text displays on the ball";
}
Essentially, this makes the text and the ball the same object (or two parts of the same object, really).
Ross Henderson
2009-07-09 15:16:25