使用字符串actionscript3应用包含补间的函数

问题描述:

这里是我的场景:使用字符串actionscript3应用包含补间的函数

我的舞台左侧有5个词汇单词。游戏开始时,第一个字移动到屏幕右侧。此时,玩家可以点击我在舞台底部的“下一个按钮”。当单击此按钮时,第二个词汇单词应该在舞台右侧放置到位,而第一个词汇单词在舞台左侧再次回到原始位置。

所有词汇单词将使用相同的动画来移动和移出位置。我粘贴了一部分我正在尝试解决的代码。这仅适用于在屏幕右侧将下一个词汇词动画到位的步骤。林相当肯定,如果我能得到这个帮助,我可以自己找出其他的一切。

希望我的不正确的代码设置的方式将给我想要完成的东西的要点。我得到的错误是::错误#1006:值不是函数。上线:“object2[animateIn]();

var animateIn:String = "moveIn"; 
function moveIn(e) : void 
{ 
    var tweenUp: Tween = new Tween(e.currentTarget, "y", None.easeNone, -125, -900, .5, true); 
    var tweenOver: Tween = new Tween(e.currentTarget, "x", None.easeNone, -125, 200, .1, true); 
    var tweenDown: Tween = new Tween(e.currentTarget, "y", Elastic.easeOut, -900, 75, 2, true); 
    var toyscaleX: Tween = new Tween(e.currentTarget, "scaleX", Elastic.easeOut, 0, 3, 2, true); 
    var toyscaleY: Tween = new Tween(e.currentTarget, "scaleY", Elastic.easeOut, 0, 3, 2, true); 
} 


//Next Button Functionality 

nextArrow.addEventListener(MouseEvent.CLICK, goNext); 
function goNext(event: MouseEvent): void { 
    if (object1.y == 75) { 
    object2[animateIn](); 
    } 

} 
+0

你能解释更多你在做什么?你是否试图将'object2'传递给'moveIn()',或者'moveIn()'是你试图调用的'object2'的函数? – akmozo

+0

是的,我希望moveIn()是单击nextArrow时object2的函数,但只有当对象1位于y的位置75时。 – Warren

+0

您不能这样做。你能解释一下为什么你需要这个,或者你想要做什么?您是否尝试将补间应用于'object2'? ... – akmozo

例如,您可以使用moveIn()功能将被实例化以创建所有对象类中:

package { 

    import flash.display.MovieClip; 
    import fl.transitions.Tween; 
    import fl.transitions.easing.*; 

    public class MyObject extends MovieClip {  

     public function MyObject() { 
      // constructor code 
     } 

     public function moveIn() : void 
     { 
      var tweenUp: Tween = new Tween(this, "y", None.easeNone, -125, -900, .5, true); 
      var tweenOver: Tween = new Tween(this, "x", None.easeNone, -125, 200, .1, true); 
      var tweenDown: Tween = new Tween(this, "y", Elastic.easeOut, -900, 75, 2, true); 
      var toyscaleX: Tween = new Tween(this, "scaleX", Elastic.easeOut, 0, 3, 2, true); 
      var toyscaleY: Tween = new Tween(this, "scaleY", Elastic.easeOut, 0, 3, 2, true); 
     } 

    } 

} 

创建该类:

那么你只需要使用它:

object2.moveIn(); 

希望能有所帮助。

+0

这有助于很多,但不工作,我想因为我试图在一个嵌套的影片剪辑内做到这一点。 – Warren

+0

@Warren这是您的MovieClip(ActionScript链接类)的类。我编辑了我的答案,看看。 – akmozo

+0

不知道我在做什么错,但我不断收到错误,类不能嵌套。我尝试删除'包'部分,仍然得到嵌套错误。 – Warren

你最好使用TweenMax,by GreenSock

下载greensock.SWC库,放在你的根附近。添加SWC到

Advance Actionscript 3.0设置 - >库路径 - >添加SWC文件

在舞台上,我已经把5部名为影片剪辑object1通过object5和SimpleButton的命名按钮

enter image description here

这是在时间轴(F9)德AS3:

import flash.display.MovieClip; 
import com.greensock.TweenMax; 

// array of all tweenable movieclips 
var words:Array = [object1, object2,object3,object4,object5]; 

// animate first word to center 
var currentWord:MovieClip = words[0]; 
animateCurrentWordToCenter(); 

// listen for button clicks 
button.addEventListener(MouseEvent.CLICK, buttonClickedHandler); 


function buttonClickedHandler(event: MouseEvent): void 
{ 
    // get index 
    var index:int = words.indexOf(currentWord); 

    // animate back to position 
    var newY:Number = (index + 1) * 50; 
    TweenMax.to(currentWord, 0.3, {x:20, y:newY, scaleX:1, scaleY:1}); 

    // calculate next index, loop back to first word 
    var nextIndex:int = (index + 1) % words.length; 
    currentWord = words[nextIndex]; 

    // animate currentWord to center 
    animateCurrentWordToCenter(); 
} 

function animateCurrentWordToCenter() 
{ 
    // syntax: TweenMax.to(<movieclip>, <duration>, <objectWithNewProperties>) 
    TweenMax.to(currentWord, 0.3, {x:150, y:200, scaleX:2, scaleY:2}); 
} 

您可能要保存原始的X,Y位置字动画到中心,并重新设置时前你动画回来,而不是我所做的,使用索引(newY)计算Y:P