Jump to content
GreenSock

icekomo

adding an array of images to my preloader?

Recommended Posts

Hello,

I have a preloader that I created using loaderMax. I got the xml and the swf file to loading. But now I would like to add an array of images, say 10 to this file, and I'm not sure what the best way to go about this would be. Any helpful hints in the right direction would be great! Here is what I have so far.

 

 

public class Preloader extends MovieClip

{

public var queue:LoaderMax = new LoaderMax({name:"mainQueue",onComplete:completeHandler,onError:errorHandler});

public var progressBar:MovieClip = new progBar_mc();

 

public function Preloader():void

{

addChild(progressBar);

//starts the load for the XML

queue.append( new XMLLoader("xml/medallion.xml", {name:"myXML",onProgress:progressHandler,onComplete:loadXml}));

//starts the load for the swf file, and adds it to this container

queue.append( new SWFLoader("medallion.swf", {onProgress:progressHandler,estimatedBytes:126000,container:this}));

 

queue.load();

progressBar.loadText.text = "loading xml";

}

 

Thanks!

Link to comment
Share on other sites

G'day mate,

 

Just quickly whipped up this for you. But you could define an array of images and then setup an ImageLoader inside a loop and append your loaderMax Object like so.

 

	//Setup Array of Images
	var aImages:Array = new Array("image1.jpg", "image2.jpg", "image3.gif", "image4.png");

	//Setup LoaderMax for preloading images
	var mainLoader:LoaderMax = new LoaderMax( { name:"mainloader" } );

	//Loop through array and add images to loadermax object
	for (var i:int = 0; i < aImages.length; i++) 
	{
		//Get filename from array
		var imageFile:String = aImages[i];
		//Setup Imageloader Object
		var iLoad:ImageLoader = new ImageLoader(imageFile, new ImageLoaderVars()
		.container(youContainerToAttachTo)
		.smoothing(true)
		);

		//Append LoaderMax Object with the imageloader we just setup
		mainLoader.append(iLoad)

	}

	//Finally load the loadermax object and all imageloaders attached to it
	mainLoader.load();

Link to comment
Share on other sites

Thanks for your help on this.

Where are you getting this from?

 

new ImageLoaderVars()

Link to comment
Share on other sites

could I also add this to direct where all my images for this loader are living?

 

iLoad.prependURLs("images/aSpot/");

Link to comment
Share on other sites

You'd probably want to prependURLs to your LoaderMax object instead of each image Loader. Would be a bit more optimized that way. So after:

mainLoader.append(iLoad)

you can do

mainLoader.prependURLs("http://www.yoururl/");

 

Also the new ImageLoaderVars() is an inline object which gives code hinting for dot syntax. You still fine to use the old approach of including your vars in a generic object and skipping the new ImageLoaderVars() object instead

etc {smoothing:true, container:true}

Link to comment
Share on other sites

I get these 2 errors:

1180: Call to a possibly undefined method ImageLoaderVars.

1061: Call to a possibly undefined method prependURLs through a reference with static type com.greensock.loading:ImageLoader.

 

 

I thought I had the correct stuff imported.

Link to comment
Share on other sites

The first error is caused by the fact that you didn't import the ImageLoaderVars class:

import com.greensock.loading.data.ImageLoaderVars;

 

The second error means you're trying to call prependURLs() on an ImageLoader instance - you can't do that. Only LoaderMax has prependURLs() (which kinda makes sense if you think about it). If you want to prepend the url of a ImageLoader directly, you'd do:

 

myImageLoader.url = "http://www.myPrefix.com/" + myImageLoader.url;

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