Hello,
I am new to greensock and my coding may be a bit of a mess however I have an urgent problem.
I created an animation and want it to repeat infinitely, however, after the second loop the animation starts to become problematic. The animations start to fire randomly and don't play like they do the first time.
If my explanation is unclear please tell me and i will clarify.
I have spent 3 hours trying various different approaches to repeating the code and i cannot find a solution.
here is the code.
stop();
//import the GreenSock classes
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;
var nT:Boolean = new Boolean();
var mO:Boolean = new Boolean();
var debug:Boolean = new Boolean();
var masterTL:TimelineMax = new TimelineMax();
//CREATES TIMELINE
masterTL.addLabel("Start", 0);
//HIDES ALL OF LAYERS BY REDUCING ALPHA TO 0
masterTL.insertMultiple([TweenLite.to(Text_S1_mc, 0, {alpha:0, x:4.75, y:30.3}),
TweenLite.to(chain_mc, 0, {alpha:0, x:265.5, y:-38.05}),
TweenLite.to(takeCon_mc, 0, {alpha:0, x:2.9, y:10.7}),
TweenLite.to(logoSm_mc, 0, {alpha:0, x:32.7, y:153.35}),
TweenLite.to(todayTxt_mc, 0, {alpha:0, x:57.05, y:62}),
TweenLite.to(sheen_mc, 0, {alpha:0, x:-41, y:150.4}),
TweenLite.to(forF, 0, {x:600, y:176.6, alpha:0}),
TweenLite.to(getYour, 0, {alpha:0, x:-2, y:-5.6}),
TweenLite.to(pullHandle_mc, 0, {alpha:0, x:255.25, y:103.9}),
TweenLite.to(pfEP, 0, {alpha:0, x:-5, y:84.1})
]);
masterTL.insert(TweenLite.delayedCall(1, Sc1St));
/**********************************************************************************************************************************************/
/************************************************************ SCENE 1 START *******************************************************************/
/**********************************************************************************************************************************************/
function Sc1St():void {
if (debug == true){
trace("scene 1 begun");
};
//TEXT APPEARS
masterTL.insert(TweenLite.to(Text_S1_mc, 1, {alpha:1}));
//CHAIN AND HANDLE APPEAR AFTER DELAY
masterTL.append(TweenLite.to(chain_mc, 0.5, {alpha:1}), 0.5);
masterTL.append(TweenLite.to(pullHandle_mc, 0.5, {alpha:1}), -0.5);
//MAKE HANDLE PULL DOWNWARDS
masterTL.append(TweenMax.to(pullHandle_mc, 0.5, {y:124.9, repeat:1, yoyo:true, ease:Quad.easeOut, delay:1}));
masterTL.append(TweenMax.to(chain_mc, 0.5, {y:-17.05, repeat:1, yoyo:true, ease:Quad.easeOut, onComplete:rTxt}), -1);
};
//ROTATE AND MOVE TEXT OFF SCREEN
function rTxt():void {
//SPIN TEXT - LASTS 4.5 SECS
masterTL.append(TweenMax.to(Text_S1_mc, 0.5, {scaleX:-1, x:239.25, repeat:8, yoyo:true, ease:Quad.easeInOut}));
//MOVE TEXT, HANDLE AND CHAIN
masterTL.addLabel("sc2St", 4.1);
if (debug == true){
trace("scene 1 end");
};
/*WHEN FINAL TWEEN COMPLETES CALL SCENE 2*/
masterTL.insert(TweenLite.delayedCall(1, Sc2St));
};
/**********************************************************************************************************************************************/
/************************************************************ SCENE 1 ENDS ********************************************************************/
/**********************************************************************************************************************************************/
/**********************************************************************************************************************************************/
/************************************************************ SCENE 2 START *******************************************************************/
/**********************************************************************************************************************************************/
function Sc2St():void{
if (debug == true){
trace("scene 2 begun");
};
masterTL.insertMultiple([TweenLite.to(Text_S1_mc, 2, {y:400, alpha:0, ease:Quad.easeOut}),
TweenLite.to(chain_mc, 2, {y:-300, alpha:0, ease:Quad.easeOut}),
TweenLite.to(pullHandle_mc, 2, {y:-294, alpha:0, ease:Quad.easeOut}),
TweenLite.to(logoSm_mc, 2, {alpha:1, delay:0.2}),
TweenLite.to(takeCon_mc, 2, {alpha:1, delay:0.2}),
TweenLite.to(todayTxt_mc, 2, {alpha:1, delay:0.2})
],"sc2St");
masterTL.append(TweenMax.to(todayTxt_mc, 0.3, {scaleX:1.2, scaleY:1.2, x:38.85, y:55, repeat:1, yoyo:true, ease:Quad.easeInOut}),-1);
if (debug == true){
trace("scene 2 end NEARLY");
};
masterTL.addLabel("sc3St", 10.5);
masterTL.appendMultiple([
TweenLite.to(sheen_mc, 0.5, {alpha:0.6}),
TweenLite.to(sheen_mc, 1, {x:255, ease:Quad.easeInOut}),
/*WHEN FINAL TWEEN COMPLETES CALL SCENE 3*/
TweenLite.delayedCall(2, Sc3St)
]);
};
/**********************************************************************************************************************************************/
/************************************************************ SCENE 2 ENDS ********************************************************************/
/**********************************************************************************************************************************************/
/**********************************************************************************************************************************************/
/************************************************************ SCENE 3 START *******************************************************************/
/**********************************************************************************************************************************************/
function Sc3St():void{
if (debug == true){
trace("scene 3 begun");
};
masterTL.insertMultiple([TweenLite.to(logoSm_mc, 2, {alpha:0}),
TweenLite.to(todayTxt_mc, 2, {alpha:0}),
TweenLite.to(takeCon_mc, 2, {alpha:0}),
TweenLite.to(forF, 0, {x:24.65, y:176.6, delay:0.5}),
TweenLite.to(logoSm_mc, 0, {x:78.5, y:40.4, scaleX:0.66, scaleY:0.66, delay:1}),
TweenLite.to(getYour, 2, {alpha:1, delay:1}),
TweenLite.to(logoSm_mc, 2, {alpha:1, delay:1}),
TweenLite.to(pfEP, 2, {alpha:1, delay:1}),
TweenLite.to(forF, 2, {alpha:1, delay:1}),
],"sc3St");
forF.addEventListener(MouseEvent.ROLL_OVER, overHandler);
forF.addEventListener(MouseEvent.ROLL_OUT, outHandler);
forF.addEventListener(MouseEvent.CLICK, clickHandler);
function overHandler(event:MouseEvent):void {
if (forF.alpha == 1 && mO == false){
masterTL.insert(TweenLite.to(forF, 0, {alpha:0.5}));
mO = !mO;
} else {
//DO NOTHING
}
}
function outHandler(event:MouseEvent):void {
if (forF.alpha == 0.5 && mO == true){
masterTL.insert(TweenLite.to(forF, 0, {alpha:1}));
mO = !mO
}else{
//DO NOTHING
};
};
function clickHandler(event:MouseEvent):void{
if (debug == true){
trace('click registered');
};
navigateToURL(new URLRequest("http://www.kegel8.co.uk/articles/pelvic-floor-exercise/how-to-do-kegel-exercises.html"));
};
if (debug == true){
trace("scene 3 end");
};
masterTL.appendMultiple([
TweenLite.to(getYour, 0, {alpha:0, delay:5}),
TweenLite.to(logoSm_mc, 0, {alpha:0, delay:5}),
TweenLite.to(pfEP, 0, {alpha:0, delay:5}),
TweenLite.to(forF, 0, {alpha:0, delay:5})]);
masterTL.append(TweenLite.delayedCall(0, done));
}
/**********************************************************************************************************************************************/
/************************************************************ SCENE 3 ENDS ********************************************************************/
/**********************************************************************************************************************************************/
//FIRES WHEN ALL ANIMATION IS DONE
function done() {
if (debug == true){
trace('im done');
};
masterTL.complete();
TweenLite.delayedCall(0, restartTheTimeline);
}
//RESTARTS THE TIMELINE
function restartTheTimeline(){
if (debug == true){
trace("restart");
};
masterTL.gotoAndPlay("Start")
}