Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
kranke

content sprite can it be custom

Recommended Posts

ImageLoader and SWFLoader now create a Sprite immediately into which the remote content will load.

 

Ok I get that the ImageLoader class creates a sprite automatically for the remote content. But what if I am already making a sprite and want to use it instead. See I already built my app using this sprite and will want to use yours with minimal refactoring. Also I am loading about 250 images.

 



for each (var nodes:Node in SGSettings.drupalSiteMap.nodes)
{		

var imageHolder:Sprite = new Sprite();
imageHolder.name = nodes.title;			

var imageLoader:SGImageLoader = new SGImageLoader(imagePath)
imageHolder.addChild(imageLoader);


imageHolder.addEventListener(SGImageLoaderEvents.IMAGE_LOADED, increaseImagesLoadedCount);

SGSettings.imageStore.push({parentId: nodes.parentNodeId, id: nodes.id, path: nodes.path,collection: nodes.collection, image: imageHolder});
}

 

So as you can see, I am storing that sprite in an array for later use. So if you will be so kind to guide me as to how to set up for LoaderMAx, here is what I was thinking.

 


var loaderQueue:LoaderMax = new LoaderMax({name:"loaderQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});


for each (var nodes:Node in SGSettings.drupalSiteMap.nodes)
{		


var imageHolder:Sprite = new Sprite();
imageHolder.name = nodes.title;	

loaderQueue.append( new ImageLoader("imagePath", {name:"nodes.title", estimatedBytes:2400, container: imageHolder}))

SGSettings.imageStore.push({parentId: nodes.parentNodeId, id: nodes.id, path: nodes.path,collection: nodes.collection, image: imageHolder});
}

 

Thanks for an awesome piece of software and any help you can lend to my app!!!

 

Fernando.

Link to comment
Share on other sites

Sure, you don't have to use the ContentDisplay if you don't want to. If you want to use your own Sprite, you can just wait for the COMPLETE event, and then use the ImageLoader's rawContent. Kinda like:

function completeHandler(event:LoaderEvent):void {
   var mySprite:Sprite = new Sprite();
   mySprite.addChild(event.target.rawContent);
}

 

Make sense?

Link to comment
Share on other sites

One more question if you will. The COMPLETE event itself will be fired after the whole queue is done... right? or will it be fired per image loader?

 

Also I am creating my sprite and the array with my objects before the COMPLETE Event (see red), so your suggestions is to create it after? Also the way I know is all loaded is that in my complete function if all of the images loaded == the image count then go ahead and execute.

 

Here is my whole class, please if you have a minute help me make sense of the LoaderMax....

 

package com.letsmota.core
{
import flash.display.Sprite;
import uk.co.richardleggett.drupal.model.Node;
import com.letsmota.events.SGImageLoaderEvents;
import com.letsmota.events.SGPreloadEvents;
import com.letsmota.content.SGImageLoader;
import com.letsmota.settings.SGSettings;

public class SGImageStorage extends Sprite
{
	private var totalImagesCount:int = 0;
	private var imagesLoaded:int;
	private var imagePath:String;
	private var planeLabels:SGPlaneLabel;

	public function SGImageStorage()
	{
		loadAllCollectionImages();

	}

	private function loadAllCollectionImages():void
	{

		for each (var nodes:Node in SGSettings.drupalSiteMap.nodes)
		{
			if (nodes.type == "collections_image" || nodes.type == "contact_page" || nodes.type == "bio_page")
			{
				totalImagesCount++;
				var imageHolder:Sprite = new Sprite();
				imageHolder.name = nodes.title;[/color]

				imagePath = String(SGSettings.baseSite + SGSettings.baseDrupal + nodes.collectionImagePath);

				var imageLoader:SGImageLoader = new SGImageLoader(imagePath)
				imageHolder.addChild(imageLoader);

				imageHolder.addEventListener(SGImageLoaderEvents.IMAGE_LOADED, increaseImagesLoadedCount);

				SGSettings.imageStore.push({parentId: nodes.parentNodeId,
											   id: nodes.id,
											   path: nodes.path,
											   collection: nodes.collection,
											   image: imageHolder});
					//trace(SGSettings.imageStore.parentId);
			}
		}
	}

	private function increaseImagesLoadedCount(event:SGImageLoaderEvents):void
	{
		event.stopImmediatePropagation();
		event.currentTarget.removeEventListener(SGImageLoaderEvents.IMAGE_LOADED, increaseImagesLoadedCount);

		//trace("This is the amount of images loaded so far", imagesLoaded);
		imagesLoaded++;

		if (totalImagesCount == imagesLoaded)
		{

			trace("All Collections Images and Thumbs Loaded, proceed");
			dispatchEvent(new SGPreloadEvents(SGPreloadEvents.ALL_COLLECTION_IMAGES_LOADED, imagesLoaded));

		}

	}

}
}

 

And lastly, if I use the event raw content that's great but if not like I do not want to use the displaycontent... :)

 

Thanks for taking the time to help.

 

Fernando

Link to comment
Share on other sites

One more question if you will. The COMPLETE event itself will be fired after the whole queue is done... right? or will it be fired per image loader?

 

A LoaderMax will dispatch its COMPLETE event when it's complete, meaning all of its children are fully loaded. If you want to know each time one of its children (or descendants actually), you'd listen for CHILD_COMPLETE events on the LoaderMax. Or if you want to listen for just specific children, you can add listeners for their COMPLETE events directly. It's a very robust and flexible event system.

 

Also I am creating my sprite and the array with my objects before the COMPLETE Event (see red), so your suggestions is to create it after? Also the way I know is all loaded is that in my complete function if all of the images loaded == the image count then go ahead and execute.

 

A loader must be complete in order for you to access its raw content (kinda makes sense), so you can either wait for the LoaderMax's COMPLETE event which means everything has loaded or listen for CHILD_COMPLETE events if you want to do something to each child as it finishes loading. Remember, you can use the LoaderEvent's "target" property to find out exactly which loader the event pertains to.

 

Once you get the hang of it, I think you'll really like how simple this makes a lot of things. :)

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