My Main class is added to the stage of my .fla and I want to remove and re-add/"restart" the class when it finishes animating. All of my animations are happening in Main and are added to the display tree inside Main. How can I run the finishNow()
function from within Main.as?
The .fla file:
var run:Main = new Main(this);
stage.addChild(run);
function finishNow() {
stage.removeChild(run);
var run:Main = new Main(this);
stage.addChild(run);
}
The Main.as file:
var stageHolder:Object;
public function Main(stageHolderTemp) {
stageHolder = stageHolderTemp;
trace(stageHolder);
}
function callFinishFunction():void {
// how to call finishNow() function from .fla file here
}
EDIT: The design of the program has changed. Still trying to do the same thing (call finishNow() function – but it is now in Program.as). It all works fine, except throws an error for program.finishNow();
:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
The .fla file:
It now does not contain any code. It is linked to Program.as.
The Program.as file:
package {
import flash.display.MovieClip;
public class Program extends MovieClip {
public function Program() {
startNow();
}
function startNow() {
var run:Main = new Main(this);
addChild(run);
}
function finishNow() {
removeChild(run);
var run:Main = new Main(this);
addChild(run);
}
}
}
The Main.as file:
package {
import flash.display.Sprite;
public class Main extends Sprite
{
var stageHolder:Object;
public var program:Program;
public function Main(stageHolderTemp) {
stageHolder = stageHolderTemp;
trace(stageHolder);
someFunctionsThatDrawGraphics();
}
function callFinishFunction():void {
// how to call finishNow() function from Program.as file here?
program.finishNow();
}
}
}