I am stuck with the ActionScript here. I have a very complex animated flash movie for eLearning. These contain around 10 to 15 frames. In each frame I am having multiple movie clip symbols. The animation has been created using a blend of scripting and also normal flash animation.
Now I want to create pause and play functionality for the entire movie. I was able to create the pause function but when i try to play the movie it behaves very strange.
I was able to develop the pause functionality by refering to the below mentioned links:
http://www.unfocus.com/2009/12/07/stop-all-child-movieclips-in-flash-with-actionscript-3-0 /
http://www.curiousfind.com/blog/174
Any help in this regard is highly appreciated as i am approaching a deadline.
I am pasting the code below:
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
import flash.utils.Timer;
import flash.events.TimerEvent;
import fl.transitions.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.events.Event;
import flash.events.MouseEvent;
stop();
// function to stop all movieclips
function stopAll(content:DisplayObjectContainer):void
{
if (content is MovieClip)
(content as MovieClip).stop();
if (content.numChildren)
{
var child:DisplayObjectContainer;
for (var i:int, n:int = content.numChildren; i < n; ++i)
{
if (content.getChildAt(i) is DisplayObjectContainer)
{
child = content.getChildAt(i) as DisplayObjectContainer;
if (child.numChildren)
stopAll(child);
else if (child is MovieClip)
(child as MovieClip).stop();
}
}
}
}
// function to play all movieclips
function playAll(content:DisplayObjectContainer):void
{
if (content is MovieClip)
{
var movieClip:MovieClip = content as MovieClip;
if (movieClip.currentFrame < movieClip.totalFrames) // if the main timeline has reached the end, don't play it
movieClip.gotoAndPlay(currentFrame);
}
if (content.numChildren)
{
var child:DisplayObjectContainer;
var n:int = content.numChildren;
for (var i:int = 0; i < n; i++)
{
if (content.getChildAt(i) is DisplayObjectContainer)
{
child = content.getChildAt(i) as DisplayObjectContainer;
if (child.numChildren)
playAll(child);
else if (child is MovieClip)
{
var childMovieClip:MovieClip = child as MovieClip;
if (childMovieClip.currentFrame < childMovieClip.totalFrames)
//childMovieClip.play();
childMovieClip.play();
}
}
}
}
}
function resetMovieClip(movieClip:MovieClip):MovieClip
{
var sourceClass:Class = movieClip.constructor;
var resetMovieClip:MovieClip = new sourceClass();
return resetMovieClip;
}
pauseBtn.addEventListener(MouseEvent.CLICK, onClickStop_1);
function onClickStop_1(evt:MouseEvent):void
{
MovieClip(root).stopAll(this);
myTimer.stop();
}
playBtn.addEventListener(MouseEvent.CLICK, onClickPlay_1);
function onClickPlay_1(evt:MouseEvent):void
{
MovieClip(root).playAll(this);
myTimer.start();
}
Other code which helps in animating the movie and other functionalities are as pasted below:
stage.addEventListener(Event.RESIZE, mascot);
function mascot():void {
// Defining variables
var mc1:MovieClip = this.mascotAni;
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
// resizing movieclip
mc1.width = sw/3;
mc1.height = sh/3;
// positioning mc
mc1.x = (stage.stageWidth/2)-(mc1.width/2);
mc1.y = (stage.stageHeight/2)-(mc1.height/2);
// keeps the mc1 proportional
mc1.scaleX <= mc1.scaleY ? (mc1.scaleX = mc1.scaleY) : (mc1.scaleY = mc1.scaleX);
stage.removeEventListener(Event.RESIZE, mascot);
}
mascot();
this.mascotAni.y = 100;
function mascotReset():void
{
// Defining variables
var mc1:MovieClip = this.mascotAni;
stage.removeEventListener(Event.RESIZE, mascot);
mc1.width = 113.45;
mc1.height = 153.85;
mc1.x = (stage.stageWidth/2)-(mc1.width/2);
mc1.y = (stage.stageHeight/2)-(mc1.height/2);
// keeps the mc1 proportional
mc1.scaleX <= mc1.scaleY ? (mc1.scaleX = mc1.scaleY) : (mc1.scaleY = mc1.scaleX);
}
var interval:int;
var myTimer:Timer;
// function to pause timeline
function pauseClips(secs:int, myClip:MovieClip):void
{
interval = secs;
myTimer = new Timer(interval*1000,0);
myTimer.addEventListener(TimerEvent.TIMER, goNextFrm);
myTimer.start();
function goNextFrm(evt:TimerEvent):void
{
myTimer.reset();
myClip.nextFrame();
myTimer.removeEventListener(TimerEvent.TIMER, goNextFrm);
}
}
// function to pause timeline on a particular label
function pauseClipsLabel(secs:int, myClip:MovieClip, myLabel:String):void
{
interval = secs;
myTimer = new Timer(interval*1000,0);
myTimer.addEventListener(TimerEvent.TIMER, goNextFrm);
myTimer.start();
function goNextFrm(evt:TimerEvent):void
{
myClip.gotoAndStop(myLabel);
myTimer.removeEventListener(TimerEvent.TIMER, goNextFrm);
}
}
MovieClip(root).pauseClips(4.5, this);
// function to fade clips
function fadeClips(target_mc:MovieClip, next_mc:MovieClip, from:Number, to:Number):void
{
var fadeTW:Tween = new Tween(target_mc, "alpha", Strong.easeInOut, from, to, 0.5, true);
fadeTW.addEventListener(TweenEvent.MOTION_FINISH, fadeFinish);
function fadeFinish(evt:TweenEvent):void
{
next_mc.nextFrame();
fadeTW.removeEventListener(TweenEvent.MOTION_FINISH, fadeFinish);
}
}
// function to fade clips with speed
function fadeClipsSpeed(target_mc:MovieClip, next_mc:MovieClip, from:Number, to:Number, speed:int):void
{
var fadeTW:Tween = new Tween(target_mc, "alpha", Strong.easeInOut, from, to, speed, true);
fadeTW.addEventListener(TweenEvent.MOTION_FINISH, fadeFinish);
function fadeFinish(evt:TweenEvent):void
{
next_mc.nextFrame();
fadeTW.removeEventListener(TweenEvent.MOTION_FINISH, fadeFinish);
}
}
// function to show screen transitions
function screenFx(target_mc:MovieClip, next_mc:MovieClip):void
{
//var tweenTW:Tween = new Tween(target_mc,"alpha",Strong.easeInOut,0,1,1.2,true);
var tranFx:TransitionManager = new TransitionManager(target_mc);
tranFx.startTransition({type:Iris, direction:Transition.OUT, duration:1.2, easing:Strong.easeOut, startPoint:5, shape:Iris.CIRCLE});
tranFx.addEventListener("allTransitionsOutDone",doneTrans);
function doneTrans(evt:Event):void
{
next_mc.nextFrame();
tranFx.removeEventListener("allTransitionsOutDone",doneTrans);
}
}
// function to show screen transitions inverse
function screenFxInv(target_mc:MovieClip, next_mc:MovieClip):void
{
var tweenTW:Tween = new Tween(target_mc,"alpha",Strong.easeInOut,0,1,1.2,true);
var tranFx:TransitionManager = new TransitionManager(target_mc);
tranFx.startTransition({type:Iris, direction:Transition.IN, duration:2, easing:Strong.easeOut, startPoint:5, shape:Iris.SQUARE});
tranFx.addEventListener("allTransitionsInDone",doneTrans);
function doneTrans(evt:Event):void
{
next_mc.nextFrame();
tranFx.removeEventListener("allTransitionsInDone",doneTrans);
}
}
// function to zoom in
function zoomFx(target_mc:MovieClip):void
{
//var tweenTW:Tween = new Tween(target_mc,"alpha",Strong.easeInOut,0,1,1.2,true);
var tranFx:TransitionManager = new TransitionManager(target_mc);
tranFx.startTransition({type:Zoom, direction:Transition.IN, duration:3, easing:Strong.easeOut});
//tranFx.addEventListener("allTransitionsInDone",doneTrans);
/*function doneTrans(evt:Event):void
{
next_mc.nextFrame();
}*/
}
// Blinds Fx
function wipeFx(target_mc:MovieClip):void
{
var tranFx:TransitionManager = new TransitionManager(target_mc);
tranFx.startTransition({type:Wipe, direction:Transition.IN, duration:3, easing:Strong.easeOut, startPoint:9});
}
// Blinds Fx Center
function fadePixelFx(target_mc:MovieClip):void
{
var tranFx:TransitionManager = new TransitionManager(target_mc);
tranFx.startTransition({type:Fade, direction:Transition.IN, duration:1, easing:Strong.easeOut});
tranFx.startTransition({type:PixelDissolve, direction:Transition.IN, duration:1, easing:Strong.easeOut, xSections:100, ySections:100});
}