Jump to content
Search Community

using an image from an XML file more then once.

icekomo test
Moderator Tag

Recommended Posts

Hello, I am building a prototype app for work, and have the app set up using loaderMax to load in an xml file with all my data. That all works great, but what I am not able to do is to use an image more then once. here is my AS:

I'm not even sure that the way I am doing this is the best way. I load my images, and then place them into an array (brewerImages).

 

private var brewerImages:Array;

brewerImages = [LoaderMax.getContent("brewer1"),LoaderMax.getContent("brewer2"),LoaderMax.getContent("brewer3"),LoaderMax.getContent("brewer4")];

 

I then pass this array to the class that I am using it in.

The class I am using this in need to use and index of the array (an image) more then once, which is where I run into problem. I was doing some research and I think that I will need to use the bitmap data for this, but I wasn't able to figure it out.

 

Any help would be wonderful!

 

Thanks!!

Link to comment
Share on other sites

yes, some of that copyPixels(), draw() and other bitmap stuff can be a little over the top.

 

i have created a very simplified file that uses an ImageLoader to load an image.

after the image has loaded, i pass the rawContent of the ImageLoader into a cloneBitmap function.

a clone of the original ImageLoader's Bitmap (rawContent) gets added to the display list and is rotated.

 

to understand the difference between the content and rawContent of a Loader here is a bit from the docs:

The ImageLoader's content refers to a ContentDisplay (Sprite) that is created immediately so that you can position/scale/rotate it or add ROLL_OVER/ROLL_OUT/CLICK listeners before (or while) the image loads. Use the ImageLoader's content property to get the ContentDisplay Sprite, or use the rawContent property to get the actual Bitmap. If a container is defined in the vars object, the ContentDisplay will immediately be added to that container).

 

 

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.loading.display.ContentDisplay;
import com.greensock.events.*;
import flash.display.Sprite;



var image_container:Sprite = new Sprite();
addChild(image_container);

var image:ImageLoader = new ImageLoader("f.jpg", {name:"sampleImage", container:image_container, onComplete:onCompleteHandler});

image.load();

function onCompleteHandler(e:LoaderEvent){

//below you would pass in a reference to your loader from the array:
//var clone:Bitmap = cloneBitmap( yourArray[someIndex].rawContent );


   //create a clone
var clone:Bitmap = cloneBitmap( LoaderMax.getContent("sampleImage").rawContent );
clone.x = 300;
clone.rotation = 45
addChild(clone);

}

//you can pass the rawContent of an ImageLoader in and get a duplicate Bitmap out
function cloneBitmap(raw:Bitmap):Bitmap {
return new Bitmap(raw.bitmapData);
}	

 

also, just so you know. LoaderMax will automatically create a Bitmap copy of a loader's content if you try to load something that has already been loaded.

from the docs:

 

[new in version 1.89:] When you load() an ImageLoader, it will automatically check to see if another ImageLoader exists with a matching url that has already finished loading. If it finds one, it will copy that BitmapData to use in its own Bitmap in order to maximize performance and minimize memory usage. After all, why load the file again if you've already loaded it? (The exception, of course, is when the ImageLoader's noCache is set to true.)

 

it might take a bit of work to make that new feature work for you with your current code structure though.

 

I think seeing the attached file work will help you understand the code above.

loadAndDuplicateImage_cs4.zip

Link to comment
Share on other sites

  • 4 weeks later...

Just picked up this thread and it's relevant to a project I'm working on.

 

So if I load one image, loading from the same URL will just copy the image rather than load it all over again - unless the noCache property is set to true? This is great - thanks ;).

 

My question is about the same thing situation with videos. I'd like to display 2 of the same videos but at slightly different times. At the moment, I load up a separate video loader with the same url, but give it a different name. Will this just "get copied" in the same way as the image does, or does it load all over again? Is there a trick I'm missing out on here?

 

Thanks for another great product.

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