2009-03-09 14 views
0

Bazı sözcüklerle bir dizi alması ve araları tek tek, belirtilen bir zaman aşımıyla uygulamak için bu kodu kullanıyorum. Sanırım boş bir movieclip yapmalıyım ve sonra bir zaman aşımıyla bir foreach döngüsüyle onları canlandırmalıyım, ama bunu tam olarak nasıl yapacağımı kaybettim.Diziden gelen metni canlandırın

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); 

gerçekten bazı yardıma ihtiyaç Could: Nerede olduğumu

budur.

cevap

3

Ben CS3 yok ama çırpılmış bir Tweener adlı ücretsiz bir ara doldurma kitaplığı kullanarak hızlı örnek. here'u bulabilirsiniz.

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] }); 
    } 
} 
+0

Teşekkürler, ancak yayınlamaya çalıştığımda bir hata alıyorum. 1114: Ortak özellik sadece bir paket içinde kullanılabilir. .fla dosyasını gönderir misiniz? –

+0

Kullandığınız geliştirme ortamı hakkında fazla bir şey bilmiyorum. Belki "public" özelliğinden "public" özelliğini kaldırmanız gerekir? –

+0

Flash CS4 kullanıyorum. "Herkesi" kaldırdığımda yeni bir hata alıyorum: 1131: Sınıflar iç içe geçmemelidir. –

0

Tween motorunuza bağlı olarak, zinciri Tweens'e sahip olabilirsiniz. Tween motorunuz tam olarak ne olduğundan emin değiliz, işte daha klasik bir yaklaşım. animateNext() fonksiyonu başlangıçta bir kez denir ve bundan sonra yalnızca son arasını doldurur onComplete işleyicisi tarafından çağrılması gereken (ya da Zamanlayıcı yöntemi):

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() 

} 
+0

Standart fl.transitions sınıfını kullanıyorum. Metni dizilerden movieclips'e ve font ile büyüklüğüne göre nasıl ekleyebilirim? –

+0

Aynı anda birkaç metin görüntülemek istiyorsanız ve her öğe için farklı yazı tipleri/stiller uygulamanız gerekirse vb. –