Jump to content
Search Community

Looking for some more options to work with!

learner_7n test
Moderator Tag

Recommended Posts

Hi,

 

The example code which I have downloaded is quite nice. But I would like to have some more options which can be more helpful for me.

 

1) x & y position values (for each object) to keep my objects wherever I want on stage.

2) width & height of my objects (for each object) to keep my objects as I like...Custom size.

The following is the code:

 

package demos {

import com.greensock.events.LoaderEvent;
import com.greensock.loading.ImageLoader;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.SWFLoader;
import com.greensock.loading.VideoLoader;
import com.greensock.loading.display.ContentDisplay;

import flash.display.Sprite;

public class Parse_Array extends Sprite {

	public var progress_mc:MovieClip;

	public function Parse_Array() {

		//activate the loaders we need
		LoaderMax.activate([imageLoader, SWFLoader, VideoLoader]); 

		var urls:Array = ["image.jpg", "video.f4v", "image.png", "avm2.swf"];
		var queue:LoaderMax = LoaderMax.parse(urls, 
											  {maxConnections:1, 
											   onProgress:_progressHandler, 
											   onComplete:_queueCompleteHandler, 
											   onChildComplete:_childCompleteHandler},
											  {width:125, 
											   height:90, 
											   scaleMode:"stretch", 
											   y:150});
		queue.prependURLs("assets/");
		queue.load();
	}

	private function _progressHandler(event:LoaderEvent):void {
		this.progress_mc.progressBar_mc.scaleX = event.target.progress;
	}

	private function _queueCompleteHandler(event:LoaderEvent):void {
		var contents:Array = event.target.content;
		var currentContent:ContentDisplay;
		for (var i:int = 0; i < contents.length; i++) {
			currentContent = contents[i];
			addChild(currentContent);
			currentContent.x = i * 125 + 25;
		}
	}

	private function _childCompleteHandler(event:LoaderEvent):void {
		trace("child loaded: " + event.target + " inside queue: " + event.currentTarget);
	}
}
}

Link to comment
Share on other sites

If you want custom sizes and positions for each object, then you should create each loader instead of trying to parse() and array of URLs. Kinda like:

 

var queue:LoaderMax = new LoaderMax();
queue.append( new SWFLoader("child.swf", {name:"swf", x:100, y:200, width:130, height:130, container:this}) );
queue.append( new ImageLoader("photo.jpg", {name:"photo", x:230, y:200, width:150, height:250, container:this}) );
...
queue.load();

 

There are tons of options and lots of flexibility. Make sure you watch all the videos and read the LoaderMax Tips & Tricks page as well as the ASDocs to really get a feel for things.

 

Have fun.

Link to comment
Share on other sites

Thank you very much for your help. It is working fine and much helpful for me. I am using the learning resources to understand it well. I just need your support for a couple of days to give my demo project a shape.

 

If you won't mind, please let me know how can I unload or make invisible my external .SWF file after displaying it for a while (say, after 5 seconds)? Really sorry to bother you asking basic question. I am downloading several free fla files to understand it.

 

Once again thanks for your kind help.

Link to comment
Share on other sites

You can simply call unload() on the loader.

 

var loader:SWFLoader = new SWFLoader("child.swf");
loader.load();

//then later...
loader.unload();

 

If you need a way to find your loader from anywhere by its name or url, just use the LoaderMax.getLoader() method, like this:

 

var loader:SWFLoader = Loader.getLoader("myLoaderNameOrURL");
if (loader != null) {
   loader.unload();
} else {
   trace("Couldn't find loader");
}

 

Have you read through the ASDocs? Those can be really helpful to explore the various methods and properties. http://www.greensock.com/as/docs/tween/_loadermax.html

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