Hi there,
I’m working on a PowerPoint-like animation. It starts with a .swf that acts as my stage and external .swf are subsequently loaded via “NEXT” buttons. My “NEXT” buttons are located inside the various external files (namely page01.swf, page03.swf, page06.swf, page09.swf, etc.)
I have a problem with the buttons when I placed the code to load the next .swf file in the .swf containing the button itself. [Example: I am in page01.swf which carries the button with instance name “next_btn01”. In the AS, the mouseclick event would trigger a load of “page02.swf”, together with removeChild().] But the problem is that I cannot advance to page03.swf without getting an "Error#1009: Cannot access a property or method of a null object reference.
I understand this Error#1009 to be caused by an event listener on my stage in the ActionScript for page02.swf, according to http://www.flashandmath.com/intermediate/swfload/ . The thing is I don’t very much understand what is being explained except that the line addChild() has to be added before the eventListener(). Can somebody tell me exactly where I should move the line addChild() to? Or is there any way to work around having to have an event listener on the stage in page02.swf?
Lastly, can anyone tell me, just by looking at the codes, whether the external .swfs are being removed/unloaded? This is because I have a “REPLAY” button at the last .swf but it only plays the last frame of each .swf during the reply instead.
ActionScript for page00.swf (which acts as my Stage)
stop();
var page:MovieClip;
var loader:Loader = new Loader();
var defaultPage:URLRequest=new URLRequest("page01.swf");
loader.load(defaultPage);
addChild(loader);
//Btns Universal Function
function btnClick(event:MouseEvent):void {
removeChild(loader);
var newPageRequest:URLRequest=new URLRequest(event.target.name + ".swf");
loader.load(newPageRequest);
addChild(loader);
}
ActionScript for page01.swf
stop();
var loader:Loader=new Loader ();
next_btn01.addEventListener(MouseEvent.CLICK, btnClick);
function btnClick(myevent:MouseEvent):void {
addChild(loader);
var newPageRequest:URLRequest=new URLRequest("page02.swf");
loader.load(newPageRequest);
removeChild(loader);
}
ActionScript for page02.swf:
stop();
var myBoundaries:Rectangle=new Rectangle(431,409,0.1,-15);
var loader:Loader=new Loader ();
MGAswitch.addEventListener(MouseEvent.MOUSE_DOWN,dragSwitch);
function dragSwitch(event:MouseEvent):void {
MGAswitch.startDrag(false,myBoundaries);
}
stage.addEventListener(MouseEvent.MOUSE_UP,dropSwitch);
function dropSwitch(event:MouseEvent):void {
MGAswitch.stopDrag();
if ((MGAswitch.hitTestObject(targetArea))) {
var newPageRequest:URLRequest=new URLRequest("page03_test.swf");
loader.load(newPageRequest);
addChild(loader);
}
}
targetArea.addEventListener(Event.ENTER_FRAME, hitTest);
function hitTest(yourEvent:Event):void {
if ((MGAswitch.hitTestObject(targetArea))) {
//trace("success");
MGA_on.alpha=1;
} else {
//trace("fail");
MGA_on.alpha=0;
}
}
loader.addEventListener(MouseEvent.CLICK, unloadcontent);
function unloadcontent(myevent:MouseEvent):void {
removeChild(loader);
}
Thanks!