-
AS3 Fading sticks
Hello
I've managed to create the code below which loads a Movie Clip from the Library. It is then randomly placed on the stage and fades in. After the fade is complete the timer even starts and when that is reached the fad out happens.
Whats going wrong is that the process runs OK until the image is faded in the third time where the timer runs and teh fade out starts. The whole think just locks up with the third image partially faded.
Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.utils.setTimeout;
var myTimer:Timer = new Timer(1500, 1);
var xPos:Number = stage.stageWidth/2;
var yPos:Number = stage.stageHeight/2;
var mc:mcLogo=new mcLogo();
mc.x= Math.floor(Math.random() * 800) + 100;//xPos;
mc.y= Math.floor(Math.random() * 600) + 100;//yPos;
addChild(mc);
mcLogoStart();
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
function mcLogoStart():void{
mc.x= Math.floor(Math.random() * (1024-(mc.width)-50))+50;
mc.y= Math.floor(Math.random() * (768-(mc.height/2)-25))+25;
var mcLogoTween:Tween = new Tween(mc, "alpha", None.easeIn, 0, 1, 2, true);
mcLogoTween.addEventListener(TweenEvent.MOTION_FINISH, freezeImage);
}
function freezeImage(e:TweenEvent):void{
//
if(mc.alpha==1){
myTimer.start();
}
if(mc.alpha==0){
mcLogoStart();
}
}
function timerHandler(e:TimerEvent):void{
mcLogoFinish();
}
function mcLogoFinish():void{
var mcLogoTweenOut:Tween = new Tween(mc, "alpha", None.easeOut, 1, 0, 2, true);
mcLogoTweenOut.addEventListener(TweenEvent.MOTION_FINISH, freezeImage);
}