Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 从数组中设置文本动画_Flash_Actionscript 3_Arrays - Fatal编程技术网

Flash 从数组中设置文本动画

Flash 从数组中设置文本动画,flash,actionscript-3,arrays,Flash,Actionscript 3,Arrays,我有一段代码,它应该获取一个包含一些单词的数组,并在指定的超时时间内一个接一个地对它们应用tweens。我想我必须把它们制作成一个空的movieclip,然后用foreach循环在超时的情况下为它们制作动画,但我不知道该怎么做 这就是我所处的位置: var array:Array = new Array("word", "is", "here"); var bounce:Function = function(mc:MovieClip):void { mc.bounce1 = new Twee

我有一段代码,它应该获取一个包含一些单词的数组,并在指定的超时时间内一个接一个地对它们应用tweens。我想我必须把它们制作成一个空的movieclip,然后用foreach循环在超时的情况下为它们制作动画,但我不知道该怎么做

这就是我所处的位置:

var array:Array = new Array("word", "is", "here");

var bounce:Function = function(mc:MovieClip):void {
mc.bounce1 = new Tween(mc, "_y", Bounce.easeOut, 35, 75, 1, true);
mc.bounce2 = new Tween(mc, "_xscale", Bounce.easeOut, 0, 400, 4, true);
mc.bounce3 = new Tween(mc, "_yscale", Bounce.easeOut, 0, 400, 4, true);
mc.bounce4 = new Tween(mc, "_alpha", Regular.easeInOut, 100, 0, 2, true);
};
array.forEach(bounce, me);

可能真的需要一些帮助。

根据您的Tween引擎,您可能能够链接Tween。 不确定你的Tween引擎到底是什么,这里有一个更经典的方法。 animateNext()函数在开始时调用一次,此后只能由最后一个Tweens onComplete处理程序(或计时器方法)调用:


根据您的Tween引擎,您可能能够链接Tween。 不确定你的Tween引擎到底是什么,这里有一个更经典的方法。 animateNext()函数在开始时调用一次,此后只能由最后一个Tweens onComplete处理程序(或计时器方法)调用:


我没有CS3,但我使用一个名为Tweener的免费tweening库快速创建了一个示例。你可以找到它


我没有CS3,但我使用一个名为Tweener的免费tweening库快速创建了一个示例。你可以找到它


我使用的是标准的fl.transitions课程。如何将数组中的文本添加到movieclips并指定字体和大小?这取决于您是否希望同时显示多个文本,以及是否需要为每个项目应用不同的字体/样式等。我使用的是标准的fl.transitions类。如何将数组中的文本添加到movieclips并指定字体和大小?这取决于您是否希望同时显示多个文本,以及是否需要为每个项目应用不同的字体/样式等。谢谢,但我在尝试发布时出错。1114:public属性只能在包中使用。你能发布.fla文件吗?我不太了解你正在使用的开发环境。也许你需要从“class Main”中删除“public”属性?我使用的是Flash CS4。当我删除“public”时,我得到一个新的错误:1131:类不能嵌套。如果你有这个问题,而你自己也无法解决,我不知道该告诉你什么。你能读懂代码吗?你知道那个错误消息是什么意思吗?这段代码还不足以作为一个示例来完成您想要的任务吗?谢谢,但是当我试图发布它时,我遇到了一个错误。1114:public属性只能在包中使用。你能发布.fla文件吗?我不太了解你正在使用的开发环境。也许你需要从“class Main”中删除“public”属性?我使用的是Flash CS4。当我删除“public”时,我得到一个新的错误:1131:类不能嵌套。如果你有这个问题,而你自己也无法解决,我不知道该告诉你什么。你能读懂代码吗?你知道那个错误消息是什么意思吗?代码是否不足以作为一个示例来完成您想要的任务?
var wordList:Array = new Array('one','two','three');

// Keeps track of the current showing word
var currentIndex:int = -1;

// Starts the animation
animateNext();

function animateNext():void
{
   // increments the word counter
   currentIndex ++;

   // resets the word count if all the words are done
   if(currentIndex >= wordList.length)
      currentIndex = 0;

   // Apply the right word here
   var word:String = wordList[currentIndex];
   trace(word);

   // animation tweens here :
   ...

   // place callback function onComplete to animateNext()

}
import flash.events.Event;
import flash.display.MovieClip;
import flash.text.TextField;    
import flash.text.TextFormat;
import flash.text.TextFieldAutoSize;
/* this is a free Tweening library. I don't have flash CS3 but this is analogous to fl.transitions.Tween */

import caurina.transitions.Tweener; 

public class Main extends MovieClip 
{
    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        /* your array of words */
        var array: Array = new Array("word", "is", "here")

        /*we'll use this to control the position of each word*/
        var x : int = 0

        var delay : Number = 0.0

        for each(var s : String in array)
        {
            var word: TextField = new TextField()
            word.autoSize = TextFieldAutoSize.LEFT

            /* here we can adjust text format */
            word.defaultTextFormat = new TextFormat(null, 75, 0xff0000)

            word.text = s
            word.x = x
            word.y = 75

            /* put the new word into our MovieClip */
            addChild(word)

            /* apply some tweens */
            bounceText(word, delay)

            /* adjust our animation and position variables */
            delay += 1.3
            x += word.width
        }
    }

    private function bounceText(a_textField : TextField, a_delay : Number) : void
    {
        /* duration of each tween */
        var t:Number = 0.75

        /* this is the "up" part of the tween, from y=75 to y=35 */
        Tweener.addTween(a_textField, { y:35, delay:a_delay, time:t, transition:"easeOutQuad" } );

        /* this is the "down" part of the tween. note the "delay" parameter is offset by the time of the first tween.
         * the "onComplete" function calls BounceText again when the second Tween is complete. If you are using fl.transitions.Tween,
         * you can add an event listener for a TweenEvent.MOTION_FINISH event, or set the "looping" property of the Tween to true.
         * */
        Tweener.addTween(a_textField, { y:75, delay:a_delay + t, time:t, transition:"easeInQuad", onComplete:bounceText, onCompleteParams:[a_textField, 0.25] } );
    }
}