Jump to content
Search Community

LoaderMax Queue Images Array event.target.content

vmedium test
Moderator Tag

Recommended Posts

So my question is.

 

How do I store the loaded images, so that I can do things with them later?

 

My _imageArray.push(event.target.content) doesn't work (which is probably obvious to everyone but me)..

 

But in the example that is what Jack tweens in the handler event (which I understand is a ContentDisplay)

 

Where am I going wrong here?

 

 

package 
{

import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;

public class LoaderMax_Image_Queue extends MovieClip
{

	private var _loader:ImageLoader;
	private var _queue:LoaderMax;
	private var _imageArray:Array;


	public function LoaderMax_Image_Queue()
	{
		_queue = new LoaderMax({name:"mainQueue",onProgress:progressHandler,onComplete:completeHandler,onError:errorHandler});
		_loader = new ImageLoader("assets/theImageBig.jpg",{name:"theImage",container:this,onComplete:onImageLoad,onProgress:onImageProgress,x:0});

		//_loader.load();

		_queue.append(_loader);
		_queue.append(new ImageLoader("assets/theImageBig2.jpg",{name:"theImage2",container:this,onComplete:onImageLoad,onProgress:onImageProgress, x:50}));
		_queue.append(new ImageLoader("assets/theImageBig3.jpg",{name:"theImage3",container:this,onComplete:onImageLoad,onProgress:onImageProgress, x:100}));
		_queue.append(new ImageLoader("assets/theImageBig4.jpg",{name:"theImage4",container:this,onComplete:onImageLoad,onProgress:onImageProgress, x:150}));

		//_queue.append( new XMLLoader("xml/doc.xml", {name:"xmlDoc", estimatedBytes:425}));
		//_queue.append( new SWFLoader("swf/main.swf", {name:"mainClip", container:this, autoPlay:false}));

		_queue.load();

	}


	private function onImageProgress(event:LoaderEvent):void
	{
		trace("onImageProgress from _loader: " + event.target.name, Math.round(event.target.progress*100));
		//trace("onImageLoad: _loader onComplete Handler: " + this.target.progress);
	}

	private function onImageLoad(event:LoaderEvent):void
	{
		trace("onImageLoad from _loader:" + event.target.name, event.target.content);
		//trace(_imageArray);

		// HOW DO I STORE WHAT HAS LOADED INTO SOME FORM OF ARRAY SO THAT I CAN DO THINGS WITH THE LOADED ITEMS?
		// OR AM I TOTALLY MISSING SOMETHING?
		_imageArray.push(event.target.content);
	}


	private function progressHandler(event:LoaderEvent):void
	{
		trace("progressHandler from _queue: "  + Math.round(event.target.progress*100));
	}
	private function completeHandler(event:LoaderEvent):void
	{
		trace("completeHandler from _queue: " +  + event.target.content);

		trace("here are the images that loaded: " + _imageArray);
	}

	function errorHandler(event:LoaderEvent):void
	{
		trace("error occured with " + event.target + ": " + event.text);
	}
}

}

Link to comment
Share on other sites

My _imageArray.push(event.target.content) doesn't work (which is probably obvious to everyone but me)..

What do you mean by "doesn't work"? Throws errors? Inserts a null object? A different type of object than you're expecting? What specifically doesn't work about it?

 

There are several ways you could store references for later:

 

1) Just store the ImageLoader instances in an array up front when you create them. You can always get their content or rawContent later.

 

-OR-

 

2) Store the urls or names in an Array and then simply use LoaderMax.getContent() or LoaderMax.getLoader() to get what you need later.

 

-OR-

 

3) If all of your loaders in the LoaderMax instance are ImageLoaders, you can get an Array of all of their content using the LoaderMax's "content" property directly.

 

Does that help?

Link to comment
Share on other sites

Note: LoaderMax VERSION: 1.6

 

This trace statement

trace("onImageLoad from _loader:" + event.target.name, event.target.content);

 

Outputs:

onImageLoad from _loader:theImage2 [object ContentDisplay]

 

 

 

This line of code:

_imageArray.push(event.target.name);

and this:

_imageArray.push(event.target);

and this:

_imageArray.push(event.target.content);

 

Produces this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at LoaderMax_Image_Queue/onImageLoad()

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at com.greensock.loading.core::LoaderCore/_completeHandler()

 

 

REDUCED CODE:

 

package 
{

import flash.display.*;
import com.greensock.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;

public class LoaderMax_Image_Queue extends MovieClip
{
	private var _queue:LoaderMax;
	public var _imageArray:Array;

	public function LoaderMax_Image_Queue()
	{
		_queue = new LoaderMax({name:"mainQueue"});
		_queue.append(new ImageLoader("assets/theImageBig2.jpg",{name:"theImage2",container:this,onComplete:onImageLoad,onProgress:onImageProgress, x:50}));
		_queue.append(new ImageLoader("assets/theImageBig3.jpg",{name:"theImage3",container:this,onComplete:onImageLoad,onProgress:onImageProgress, x:100}));
		_queue.append(new ImageLoader("assets/theImageBig4.jpg",{name:"theImage4",container:this,onComplete:onImageLoad,onProgress:onImageProgress, x:150}));
		_queue.load();
	}
	private function onImageProgress(event:LoaderEvent):void
	{
		trace("onImageProgress from _loader: " + event.target.name, Math.round(event.target.progress*100));
	}

	private function onImageLoad(event:LoaderEvent):void
	{
		trace("onImageLoad from _loader:" + event.target.name, event.target.content);
		_imageArray.push(event.target.name);
	}
}

}

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.
×
×
  • Create New...