Hi, here I want to share you my first experience in Flash development.

Recently I want to made fadein/fadeout effect for some TextField in my application.

Below you can see code of Utils.as class. The code is pretty simple.

package {
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.utils.Timer;

public class Utils {
    public function Utils() {
    }

    static public function fadeInOut(obj:TextField, isFadeIn:Boolean):void {
        var timer:Timer;
        timer = new Timer(1, 20);
        timer.addEventListener(TimerEvent.TIMER, TimerTask);
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, TimerCompleteTask);
        timer.start();

        function TimerTask(e:TimerEvent):void {
            if (obj.alpha < 0.9 && isFadeIn) {
                obj.alpha += 0.15;
            }
            if (obj.alpha > 0 && !isFadeIn) {
                obj.alpha -= 0.05;
            }
        }

        function TimerCompleteTask(e:TimerEvent):void {
            timer.stop();
        }
    }
}
}

That’s all.
NOTE: Please, tell me if you got the better solution. Thanks!


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.