Jump to content
GreenSock

ElectricEnjin

Accessing root of swf

Recommended Posts

Hey,

 

I'm having trouble accessing a public function inside a document class in one of the loaded swfs. I was originally just using the standard As3 loaders, and it worked fine. Decided to give loadermax a whirl as it seemed cleaner and more efficient as all greensock classes are. Any thoughts to this nooby mistake? I've prioritized the items so I don't have nested movieclips inside a function like you have it on the tips and tricks page...unless theres a better method of doing this and accessing the root later on to all swf's.

 

Error: TypeError: Error #1006: initFrame is not a function.

 

private var containerArr:Array;
private var counter:Number = 0;
private var queue:LoaderMax;
private var assetLoader:SWFLoader;

public var _contactHolder:MovieClip = new MovieClip();
public var _scheduleHolder:MovieClip = new MovieClip();
public var _orderHolder:MovieClip = new MovieClip();
private var _frameHolder:MovieClip = new MovieClip();
private var _bgHolder:MovieClip = new MovieClip();

private function loadAssets():void
{
containerArr = new Array(_frameHolder, _bgHolder, _contactHolder, _scheduleHolder, _orderHolder);

queue = new LoaderMax({name:"swfQueue", autoDispose:true, onComplete:completeHandler, onError:errorHandler, maxConnections:1});
queue.append(assetLoader = new SWFLoader(_frame, {name:"frame", container:frame_mc, onComplete: addSwf}));
queue.append(assetLoader = new SWFLoader(_bg, {name:"bg", container:background_mc, onComplete: addSwf}));
queue.append(assetLoader = new SWFLoader(_contact, {name:"contact", onComplete: addSwf}));
queue.append(assetLoader = new SWFLoader(_schedule, {name:"schedule", onComplete: addSwf}));
queue.append(assetLoader = new SWFLoader(_order, {name:"order", onComplete:addSwf}));

LoaderMax.prioritize("frame");
queue.load();																									
}

private function errorHandler(e:LoaderEvent):void
{
trace("error: " + e);
}

private function addSwf(e:LoaderEvent):void
{
containerArr[counter] = e.target.rawContent;
trace(e.target.rawContent);
counter++
}

private function completeHandler(e:LoaderEvent):void
{
_frameHolder.initFrame(); //this is the function I get the error with
}

Link to comment
Share on other sites

You were storing the rawContent in your array, but when you tried to reference it, you didn't use the array - you just used _frameHolder which is merely an empty MovieClip that you created as a variable. In other words, _frameHolder wasn't the rawContent.

 

You could simplify your code quite a bit - it could look something like:

 

private var queue:LoaderMax;	  
public var _contactLoader:SWFLoader;
public var _scheduleLoader:SWFLoader;
public var _orderLoader:SWFLoader;
private var _frameLoader:SWFLoader;
private var _bgLoader:SWFLoader;

private function loadAssets():void {
  queue = new LoaderMax({name:"swfQueue", autoDispose:true, onComplete:completeHandler, onError:errorHandler, maxConnections:1});
  queue.append( _frameLoader = new SWFLoader(_frame, {name:"frame"}) );
  queue.append( _bgLoader = new SWFLoader(_bg, {name:"bg"}) );
  queue.append( _contactLoader = new SWFLoader(_contact, {name:"contact"}) );
  queue.append( _scheduleLoader = new SWFLoader(_schedule, {name:"schedule"}) );
  queue.append( _orderLoader = new SWFLoader(_order, {name:"order"}) );
  queue.load();                                                                           
}

private function errorHandler(e:LoaderEvent):void {
  trace("error: " + e);
}

private function completeHandler(e:LoaderEvent):void {
  _frameLoader.rawContent.initFrame();
}

 

If you need to reference the loaders or their content later, you should NOT set the LoaderMax's autoDispose to true - that will dispose of all the child loaders too.

 

Hope that helps.

Link to comment
Share on other sites

genius! i'm such a noob :) Thanks for your help, very much appreciated!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×