Hey eveyone,
These forums have been extremely helpful while working on my current project so I figure I’d give it a shot and post this issue.
In a nutshell, this project is an eLearning course template. It needs to be able to load/unload individual page swf and these page swfs need to communicate back up the chain to some level for this like module / course completion.
On the stage I have a pageLoader_mc linked to a PageLoader class. What I need up doing is added my LoaderObject to the display list of my pageLoader_mc MovieClip:
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.net.*;
import flash.display.*;
public class PageLoader extends MovieClip {
private var pageLoader:Loader = new Loader();
private var defaultPageLoaded:Boolean = false;
public var image_mc:MovieClip; //image_mc refers to the loaded swf image for the course player.
public function PageLoader() {
// constructor code
pageLoader.name = "myLoader";
pageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
}
//----------------------------------------------------------------------------
// Private functions
//----------------------------------------------------------------------------
private function loadComplete(evt:Event):void{
//pageLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadComplete);
addChild(pageLoader);
if(!defaultPageLoaded){
defaultPageLoaded = true;
}
dispatchEvent(new Event("onLoadComplete"));
}
//----------------------------------------------------------------------------
// Public functions
//----------------------------------------------------------------------------
public function unloadPage():void{
dispatchEvent(new Event("pageRemoved"));
removeChild(pageLoader);
}
public function runCuePoint():void{
//this.child.play();
}
public function toggleNextBtn():void{
dispatchEvent(new Event("toggleNextBtn"));
}
//----------------------------------------------------------------------------
// Get/Set functions
//----------------------------------------------------------------------------
public function set loadPage(_url:String):void{
var url:URLRequest = new URLRequest(_url);
// Checking to see if first page has already been loaded.
if (defaultPageLoaded){
unloadPage();
}
pageLoader.load(url);
}
}
}
I read a few of the post where users have done something like:
private function loadComplete(evt:Event):void{
image_mc = MovieClip(evt.target.content);
addChild (image_mc);
}
public function unloadPage():void{
dispatchEvent(new Event(“pageRemoved”));
removeChild(image_mc);
image_mc = null;
}
The Swf of the course loads. When you go to another page after it unloads the SWF I get an error:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::AVM1Movie@37710d61 to flash.display.MovieClip.
at PageLoader/loadComplete()
The Overall question, is how can I instance that loaded SWF so I can listen to custom events? In my loaded swf I guess I can “MovieClip(stage.pageLoader_mc).CallMyFunction” its just that I assume there is a way to accomplish what I’m thinking.