I want to remove and re-add/"restart" the Main class when it finishes animating. All of my animations are happening in Main and are added to the display tree inside Main. Program.as handles all this by adding/removing Main. How can I run the finishNow()
function inside Main.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:
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();
}
}
}