Script: Tweens with actionscript: fading

There are two ways to create tweens: using frame to frame animation and using actionscript. What is the advantage using actionscript? There are several advantages: filesize and easy manipulation by just changing numbers and tweens of dynamically loaded objects. The actionscript tweens also seem to be dependent on the frame rate like frame to frame tweens. I found one disadvantage changing the width of an object with actionscript, which is that everything seems to slow down if the object is very big and you are using a modem. You can see an example of all tweens combined in the "Disco" movie. The scipt for alpha tween is shown below. As an example I have chosen static text.

//main function with fadeSpeed as argument
MovieClip.prototype.fadeIn=function(fadeSpeed){
    //we first set the object's alpha value to 0.
    mytext._alpha = 0;
    //event handler
    this.onRollOver=function(){
        //defining the interval function
        myPause = new Object();
        myPause.interval = function() {
        //if alpha is less than 100...
            if(mytext._alpha<100-fadeSpeed){
                //alpha will be incremented by the fadespeed value.
                mytext._alpha+=fadeSpeed;
            }else {
                //once reached alpha is 100 and interval is stopped.
                mytext._alpha = 100;
                clearInterval(myTimer);
            }			
        }
        //starting the interval with 100 as the interval value
        myTimer = setInterval( myPause, "interval", 100);
    }
    //the same again for fading out.
    this.onRollOut=function(){
        myPause = new Object();
        myPause.interval = function() {
            if(mytext._alpha<=100){
                mytext._alpha-=fadeSpeed;
            }else {			
                mytext._alpha = 0;
                clearInterval(myTimer);
            }			
        }
        myTimer = setInterval( myPause, "interval", 100);
    }	
}
button1.fadeIn(10);	

Dynamic text tween

For dynamic text the font has to be embedded to do the same thing. Embedding dynamic font is done in the following way. Open the symbol library and go to the menu and click on new font. Give a new name for the font like "fontnameEmbed". Then write the name of the font (for example "Times") in the line called "font" and click ok. The font is now in the library. Now highlight the font symbol in the library and in the menu go to "linkage" and check the box which says "Export for actionscript". If you are loading the movie into a movieclip like I did here you have to do the same procedure in the parent movie also. Otherwise it would not work.

In the action keyframe put the following script. You can of course add things for you textfield.

//create new dynamic textfield
this.createTextField("dynamicText",5,200,60,240,40);
//set embbedding fonts true
dynamicText.embedFonts=true;
//write you text here
dynamicText.text="Dynamic Textfield";
//define some style properties and include the name of the font
textStyle = new TextFormat();
textStyle.font="impactEmbed";
textStyle.color=0xFF0000;
textStyle.size=30;
dynamicText.setTextFormat(textStyle);

Changing width and moving tweens

To change the width of an object like a curtain for example instead of alpha use "_width" and the values and for moving an object replace it by "_x" or "_y" or both. Download the sample file and check the scripts. There is also another script for dynamically created objects, which is similar as for other objects.