Monday, 11 October 2010

Gun shot text effect in Actionscript 3

In this post I have converted the gun shot text effect into Actionscript 3 code. The first three steps are exactly the same so I have not type them out in this post. Once you have completed these steps, gives each of the letters on the stage appropriate instance names. I have named my movie clips: letter1, letter2 etc.  Then open the Actions panel and enter the following code: 

//Import the packages needed.
import com.greensock.*

//Array to hold the letter movie clips.
var letterArray = [];

//This adds the names of the movie clip into the array. I 
//have saved time by using a For loop and the getChildByName()
//method to add all the name of the movie clips into the array.
for(var i:uint = 1; i < numChildren+1; i++){
    letterArray.push(getChildByName("letter"+i));
}

//This sets all the movie clips with alpha at 0 and scaleX & Y at 1.5;
for(var j:uint = 0; j < letterArray.length; j++){
    letterArray[j].alpha = 0;
    letterArray[j].scaleX = 1.5;
    letterArray[j].scaleY = 1.5;
}

//Counter to hold the current position of the array.
var counter:int = 0;

//This function tweens each letter in turn by 
//setting the alpha at 1 and scaleX & Y at 1;
function startText():void{
    TweenMax.to(letterArray[counter], 1, {alpha:1,scaleX:1, scaleY:1, onComplete: nextText});                                                                
}

//This increments the counter so the next letter can be tweened.
function nextText():void{    
    if(counter == letterArray.length-1){
        return;
    }else{
        counter++;
        startText();
    }
}

startText();

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP