Jump to content
Search Community

Remove Images from XMLLoader

alflasy test
Moderator Tag

Recommended Posts

Hi,

I know I wanted to this but not sure when and now its the right time to ask after spending three hours of searching.

 

I am loading bunch of images through xml file. Its a slide by slide images with information. While user is browsing at slide 5 users are ask to select division. After the division is selected and submit button is hit the slide show is reloaded with same slide except some.

 

So, I want to remove some images from images on fly without editing the XML. I was looking in to remove() but can't find much information about how to do that. 

 

Here is my xml file and I want to remove all the image that has attribute remove=true

 <ImageLoader name="img_1" url="5.jpg" remove='true'></ImageLoader>
<ImageLoader name="img_2" url="6.jpg"></ImageLoader>
<ImageLoader name="img_3" url="7.jpg" ></ImageLoader>
<ImageLoader name="img_4" url="8.jpg" remove='true'></ImageLoader?

Thanks

Link to comment
Share on other sites

You can use XMLLoader.getChildren() method to get an Array of all the loaders it is supposed to load.

You should be able to then loop through that array of loaders and see which ones have the remove attribute and dispose them. 

 

The third code sample of the XMLLoader docs talks about getting the xml attributes associated with a loader's XML node. 

Link to comment
Share on other sites

Got it and working but also throwing error. any idea?

function imageLoadComplete(event:LoaderEvent):void {
	if(event.target.vars.divsn){
		trace(event.target.vars.rawXML)
		event.target.vars.rawXML.dispose(true)
	}
}

I thought onInit would be best place to dispose that part of XML but was not able to get attribute and target the XML node to remove.

 

Thanks

Link to comment
Share on other sites

Not sure what the error is as you didn't mention it, but I would guess it is this line:

event.target.vars.rawXML.dispose(true)

rawXML is literally just an XML Object. dispose() is a method of various LoaderMax loaders (SWFLoader, ImageLoader, XMLLoader etc). Not sure why you are calling dispose on rawXML.

 

If you want to clean up the XML prior to it being searched for LoaderMax-related nodes like <ImageLoader> then yes, you would do that using the XMLLoader's onInit callback.

 

I'm confused as to why you are doing XML-related cleanup using an imageLoadComplete method. I thought the point was not to load certain images that have certain xml attributes.

Link to comment
Share on other sites

Yes, the error is due to this line.

event.target.vars.rawXML.dispose(true)

Actually I don't want to load any content from that XML node. Like if I have total 10 slides then when reload a function will look for remove attribute if two found then it should only load 8 slides.

 

So when I just disposed event.target then image is removed but the content is loading and so the slide number stays same. Thats why I am disposing XML node.

Link to comment
Share on other sites

So,I tried to dispose the xml child in InIt event but it thows error not not sure if that can be done below is my code

 

function moduleXMLLoaderInit(event:LoaderEvent):void {
//trace("init " + moduleXMLLoader.content.children().@remove); // Works
var getChildrenNum = moduleXMLLoader.content.children();
 for(var ch=0; ch<getChildrenNum.length();ch++){
  trace(getChildrenNum[ch].@remove)// WOrks
 if(getChildrenNum[ch].@remove== 'true'){
 getChildrenNum[ch].dispose(true);//ERROR
 }
 }

ERROR

TypeError: Error #1006: value is not a function.
	at module_fla::MainTimeline/moduleXMLLoaderInit()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at com.greensock.loading::XMLLoader/_receiveDataHandler()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at flash.net::URLLoader/onComplete()

I tried getChildren() but that didn't work in Init event. As I think it expecting the children name as parameter and it cannot be predicted in my case.

Link to comment
Share on other sites

I think I got it now. the below code works for me but not sure its the right way to do it.

function moduleXMLLoaderInit(event:LoaderEvent):void {
	 var getChildrenNum = moduleXMLLoader.getChildren()[0].getChildren();
	  for(var ch=0; ch<getChildrenNum.length;ch++){
		  if(getChildrenNum[ch].vars.rawXML.@remove== 'true'){
			  getChildrenNum[ch].dispose(true)
		  }
	  }
}
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...