Jump to content
Search Community

Loading assets and variables in a loop

davivid test
Moderator Tag

Recommended Posts

Hi,

 

Looking at my code I know there must be a better way of doing this. Take for instance this XML:

 

  

        

        

        

    

 

I am then using the following to extract the graphic, and additional data:

 

   for (var i:int; i < 6; i++)
		{	var design:Sprite = LoaderMax.getContent("card"+i);
			var bmd:BitmapData = new BitmapData(2152, 1416, true, 0x00ffffff);
			bmd.draw(design);
			var bm:Bitmap = new Bitmap(bmd);
			var photoPos:Point = new Point();
			var loader:ImageLoader = LoaderMax.getLoader("card" + i);
			photoPos.x = loader.vars.xpos;
			photoPos.y = loader.vars.ypos;
			_designs.push([bm, photoPos]);
		}

 

How do I go about doing this in a better more simplified way? I would like to think I can access all of this in a clean loop using LoaderMax name="designs".

 

Thanks.

Link to comment
Share on other sites

I really don't see anything wrong or improper with what you are doing.

 

if you want an array of all the ImageLoaders from your xml you could do

 

yourXMLLLoaderInstance.getChildren() // it takes some important parameters

public function getChildren(includeNested:Boolean = false, omitLoaderMaxes:Boolean = false):Array

 

docs: http://www.greensock.com/as/docs/tween/ ... tChildren()

 

then you would have an array to loop through... so not much different then what you are doing.

 

---------

 

another option would be to give all the ImageLoaders an onComplete handler that calls a single function that extracts the image.

Link to comment
Share on other sites

Thanks for the tip. I think I was mostly trying to see how I would acquire all the data from one loader, instead of calling LoaderMax.getContent and LoaderMax.getLoader as in my previous post, and realised I could do as below:

 

if (file)
		{
			var loader:ImageLoader = LoaderMax.getLoader(file);

			var s:Sprite = loader.content;
			var bmd:BitmapData = new BitmapData(890, 586, true, 0x00ffffff);
			bmd.draw(s);
			_preview = new Bitmap(bmd);
			_point.x = loader.vars.xpos;
			_point.y = loader.vars.ypos;
			_hiresFile = loader.vars.hires;
			_name = loader.vars.name;
			_text = loader.vars.text;
		}

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