How to make fadein / fadeout effect for TextField using only ActionScript 3.0 in Flash

Published by Igor Khrupin on

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 & lt; 0.9 & amp;& amp; isFadeIn) { obj.alpha += 0.15; } if (obj.alpha & gt; 0 & amp;& amp; !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

Avatar placeholder

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.