Jump to content
Search Community

how to remove Content Loaded By Loader Max/Image Loader

kirtan test
Moderator Tag

Recommended Posts

I loaded Image with ImageLoader like below code where resourceInfoObj is custom class holding position and size information related to image.

 

private var imageLoader:ImageLoader;
private var imageContainer:ContentDisplay;

resourceInfoObj = resourceListObj.getResourceInfoById(ResourceList.SELECTED_ITEM_IMAGE);
imageLoader = new ImageLoader(_itemPhotoUrl, new ImageLoaderVars()
										.name("itemImage")
										.bgColor(0xFF0000)
										.centerRegistration(true)
										.scaleMode("proportionalInside")
										.onComplete(itemPhotoLoadComplete)
										.x(resourceInfoObj.x)
										.y(resourceInfoObj.y)
										.width(resourceInfoObj.width)
										.height(resourceInfoObj.height));

imageLoader.load();

 

and Later When Complete Event if Fired I Added Content to Stage Like below.

 

private function itemPhotoLoadComplete(e:LoaderEvent):void
{
imageContainer = e.target.content;
this.addChild(imageContainer);
}

now after loading that photo i when use click Next/Some Button on the stage i want to remove that loaded image/imageContainer from stage and replace it with updated new url image. but when I try to remove image Loader Remains on stage.

 

to add New Updated Image i use code like below

 

public function removePreviousImage():void
{
   if (imageContainer != null)
   {
removeChild(imageContainer);
   }

}

public function UpdateContent(Newurl:String):void
{
removePreviousImage();
resourceInfoObj = resourceListObj.getResourceInfoById(ResourceList.SELECTED_ITEM_IMAGE);
imageLoader.url = Newurl;
imageLoader.vars =new ImageLoaderVars()
			.name("itemImage")
			.bgColor(0xFF0000)
			.centerRegistration(true)
			.scaleMode("proportionalInside")
			.onComplete(itemPhotoLoadComplete)
			.x(resourceInfoObj.x)
			.y(resourceInfoObj.y)
			.width(resourceInfoObj.width)
			.height(resourceInfoObj.height);
imageLoader.load();
}

Link to comment
Share on other sites

i think the issue may be that the same image is being loaded twice.. and not that the imageContainer isn't being removed.

 

for instance, in the code below you pass Newurl into the function, but I don't see where you use a new url for the ImageLoader

 

public function UpdateContent(Newurl:String):void
{
 removePreviousImage();
 resourceInfoObj = resourceListObj.getResourceInfoById(ResourceList.SELECTED_ITEM_IMAGE);
imageLoader.vars =new ImageLoaderVars()
           .name("itemImage")
           .bgColor(0xFF0000)
           .centerRegistration(true)
           .scaleMode("proportionalInside")
           .onComplete(itemPhotoLoadComplete)
           .x(resourceInfoObj.x)
           .y(resourceInfoObj.y)
           .width(resourceInfoObj.width)
           .height(resourceInfoObj.height);
imageLoader.load();
}

Link to comment
Share on other sites

glad you got it working.

 

imageLoader.url = "Some Url " and call Load() method again does that previous image still in memory of loader ?

 

i'm not exactly sure :shock: but to be safe I would call load() and pass in the "flushContent" param as true

 

imageLoader.load(true);

 

from the docs:

 

public function load(flushContent:Boolean = false):void

Loads the loader's content, optionally flushing any previously loaded content first. For example, a LoaderMax may have already loaded 4 out of the 10 loaders in its queue but if you want it to flush the data and start again, set the flushContent parameter to true (it is false by default).

 

Parameters

flushContent:Boolean (default = false) — If true, any previously loaded content in the loader will be flushed so that it loads again from the beginning. For example, a LoaderMax may have already loaded 4 out of the 10 loaders in its queue but if you want it to flush the data and start again, set the flushContent parameter to true (it is false by default).

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