Jump to content
GreenSock

macguffin

Name the loader-ID when using LoaderMax.parse()

Recommended Posts

Hi I need to give my loaders created from parsing an array a specific ID based on the file name.

 

I have done it but wanted to check that there wasn't a simpler (built in) way of doing it, as even though it works it seems a little long winded.

 

So I create a LoaderMax with an onChildOpenHandler:

var subLoadqueue : LoaderMax = LoaderMax.parse(anArrayOfURLS, {onChildOpen:childOpenHandler});

 

The handler gets the file location and then extracts just the file name using makeLoaderID(event) returns this name and sets it as the event.target.name.

 

private function childOpenHandler(event : LoaderEvent) : void {

if (event.target.name.toLocaleLowerCase().indexOf('loader') != -1) {	
               //this stops the renaming of any non automatically named loaders
		event.target.name = makeLoaderID(event);
               }
		var $tempArray : Array = String(event.target).split(' ');
		IWGstore.loaderContent.push($tempArray);
	}

 

private function makeLoaderID(event : LoaderEvent) : String {
		var $tempArray : Array = String(event.target).split(' ');
		var loaderID : String = 'empty';
		if ($tempArray[2] != null) {
			var path : Array = $tempArray[2].split('/');
			loaderID = path[path.length - 1].substr(0, loaderID.lastIndexOf('.'));
			}
		return loaderID;
	}

 

So -FILELOCATION: (file:///e|/%7e%7ework/%7ecamelot/%7egames/newgames/asset_MC1.swf) gives me

loaderContent-ID: asset_MC1

which I can then use to retrieve content in the usual way (LoaderMax.getLoader('asset_MC1').rawContent)

 

Cheers

Link to comment
Share on other sites

i don't know if there is a terribly easier way, but to make it a little simpler, instead of converting event.target to a string and trying to parse out the url you can grab the url directly:

 

event.target.url

 

 

I don't know if this is any better than re-naming the loaders, but you could also just store references to your loaders in your own associative array:

 

var  subLoaders:Array  = []

 

and then in onChildComplete (after pulling out the custom name) you could add the loader to the array:

 

subLoaders["parsedUrlID"] = event.target;

 

to access each loader you could use:

 

subLoaders_arr["parsedUrlID"].rawContent

 

instead of

 

LoaderMax.getLoader("parsedUrlID").rawContent

 

again I don't know if there is a huge advantage here other than not having to write LoaderMax.getLoader all the time OR if there is anything inherently wrong with renaming loaders (as you are doing).

Link to comment
Share on other sites

Thanks for taking the time to reply.

 

Cheers

Matt

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.
×