如何在动画片段移动,文本移动时将文本添加到移动的动画片段动态

时间:2009-07-09 02:03:57

标签: actionscript-3

我有一个加载的swf fil,在这个文件中,一个名为ball的影片剪辑,当我按下一个按钮时,这个movieclip移动,此刻,我想在这个movieclip上添加一个文本,因为movieclip移动,文本移动好像它们是同一个对象

2 个答案:

答案 0 :(得分:0)

嗯。我不确定你到底想做什么,但如果我理解正确,有几种方法可以实现这一点。

选项1:

button.addEventListener(MouseEvent.CLICK, followFunc);

private function followFunc(event:MouseEvent):void {
    removeChild(text);
    movieClip.addChild(text);
}

选项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;
}

答案 1 :(得分:0)

由于球在时间轴上,最简单的方法可能是将一个文本域放在球所在的同一个MovieClip中。像球一样的东西在第1层,而文本域在第2层。

按照您希望的方式将文本字段放在球上。

你需要命名文本字段 - 类似'ballTextField',也许。

将球添加到舞台上时(在Flash创作环境中或以编程方式)将球命名为MovieClip。称之为“球”。

然后:

button.addEventListener(MouseEvent.CLICK, buttonClickListener);

private function buttonClickListener(e:MouseEvent):void
{
    ball.ballTextField.text = "Hi.  This text displays on the ball";
}

基本上,这会使文本和球成为同一个对象(或者同一个对象的两个部分)。

相关问题