I am using the following to add a repeating animation.
var recC01: cube01;
function attachC1() {
recC01 = new cube01();
recC01.x = -158;
recC01.y = 159;
addChild(recC01);
trace("cube1");
}
var myIntervalC1: uint = setInterval(attachC1, 500);
Here is the code to remove the animation:
btnBACK.addEventListener (MouseEvent.CLICK, back1);
function back1(event:MouseEvent) :void {
gotoAndPlay(2);
var removeTimer;
clearInterval(myIntervalC1);
recC01.parent.removeChild(recC01);
trace ("back1") ;
}
The repeating animations are added at various keyframes with unique names. ie. recC01, recC02, etc. as well as attachC1, attachC2, etc.
During playback the user is able to click a "Back" button to rewind to the previous section. I am struggling because the button appears on the timeline before the instances so I cannot use clearInterval and Removechild for an instance that does not yet exist. I'd like to avoid creating unique var everytime a new child is added. Keeping track of that would be crazy.
The user could click the back button before any of these are loaded or in between say recC01 and recC02...
What is the best way to remove all of the child instances? Is there a method to listen for the Interval and Child and remove them all?
This a small screen capture of the animation. The boxes represent the liquid flow
UPDATES I thought I would update here instead of in comments. I"ve added this to frame 2:
var cubeContainer:Sprite = new Sprite();
addChild(cubeContainer);
Code that loads repeating animation.class
var recC01: cube01;
function attachC1() {
recC01 = new cube01();
recC01.x = -158;
recC01.y = 159;
cubeContainer.addChild(recC01);
trace("cube1");
}
var myIntervalC1: uint = setInterval(attachC1, 500);
Code for Back button:
btnBACKp1.addEventListener(MouseEvent.CLICK, back1);
function back1(event: MouseEvent): void {
cubeContainer.removeChildren();
gotoAndPlay(2);
trace("backFrame2");
}
Unloads for a second and then resumes loading. Could this be a result of the Interval? Previous code to unload individual instances, I had to removeInterval