Jump to content
Search Community

Pain in the butt problem- LoaderMax - XMLList

Guest acers
Moderator Tag

Recommended Posts

So I'm a basic to low level as3 coder. My problem seems to be so simple, however I have hit the wall with working out the answer. My code is just loading out some XML images into a container. Which should populate into the thumbholder:MovieClip. It does not do this ---it returns the following code.

 

Error returned is-

 

/Users/**/Documents/**/Site/of**ton/src/couk/*****/BethPage.as, Line 36	1120: Access of undefined property thumbsLoaded.

 

(I have added ////LINE36 where the offending line code is)

 

package co.uk.********
{
import com.gaiaframework.templates.AbstractPage;
import com.gaiaframework.events.*;
import com.gaiaframework.debug.*;
import com.gaiaframework.api.*;
import flash.display.*;
import flash.events.*;
import com.greensock.TweenMax;
import com.greensock.loading.XMLLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.ImageLoader;
import com.greensock.loading.data.ImageLoaderVars;

public class BethPage extends AbstractPage
{	
	public var thumbholder:MovieClip;

	public function BethPage()
	{
		super();
		alpha = 0;

		var xPhoto:XMLLoader = new XMLLoader("image.xml");
		xPhoto.addEventListener(LoaderEvent.CHILD_COMPLETE, xmlLoaded);
		xPhoto.load();			
	}

	private function xmlLoaded(e:LoaderEvent):void
	{
		var xData:XML = e.target.content;
		var xImgList:XMLList = new XMLList(xData.img);
		//set up maxObject
		var thumbLoader:LoaderMax = new LoaderMax( {name:"thumbLoader"} );
///LINE36			thumbLoader.addEventListener(LoaderEvent.COMPLETE, thumbsLoaded);
		for (var i:int = 0; 1< xImgList.length(); i++)
		{
			var iLoad:ImageLoader = new ImageLoader("assets/beth/" + xImgList[i].@url, new ImageLoaderVars()
			.name(xImgList[i].@name)
			.width(150)
			.height(150)
			.smoothing(true)
			.container(thumbholder)
			)
			thumbLoader.append(iLoad);
		}
		thumbLoader.load();
	}
	override public function transitionIn():void 
	{
		super.transitionIn();
		TweenMax.to(this, 0.3, {alpha:1, onComplete:transitionInComplete});
	}
	override public function transitionOut():void 
	{
		super.transitionOut();
		TweenMax.to(this, 0.3, {alpha:0, onComplete:transitionOutComplete});
	}
}
}

 

I would would really appreciate some help and I'm sorry if this bores you! Thanks in advance

Link to comment
Share on other sites

thumbLoader.addEventListener(LoaderEvent.COMPLETE, thumbsLoaded);

 

in that line you reference thumbsLoaded but that function does not exist.

 

you can try adding

 

function thumbsLoaded(event:LoaderEvent):void{
   trace("all thumbs loaded");
}

 

 

even with line 36 commented out and not having thumbsLoaded() in place, your images should show up as you are specifying .container(thumbholder) in your ImageLoaderVars.

 

is thumbHolder a movie clip symbol on the stage? I see you declare

 

public var thumbholder:MovieClip;

 

but i don't see in your code that the thumbholder MovieClip was ever created.

 

can you do a

 

trace(thhumbholder) 

 

inside your xmlLoaded function and confirm that it is really there?

Link to comment
Share on other sites

OK thank you very much for the reply, indeed I have placed an empty movieClip on the stage.

 

An instance of: thumbholder_mc

An instance name of: thumbholder

 

package co.uk.*******
{
import com.gaiaframework.templates.AbstractPage;
import com.gaiaframework.events.*;
import com.gaiaframework.debug.*;
import com.gaiaframework.api.*;
import flash.display.*;
import flash.events.*;
import com.greensock.TweenMax;
import com.greensock.loading.XMLLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.ImageLoader;
import com.greensock.loading.data.ImageLoaderVars;

public class BethPage extends AbstractPage
{	
	public var thumbholder:MovieClip;
	trace("trace1");
	public function BethPage()
	{
		super();
		alpha = 0;
		LoaderMax.activate([xmlLoader]);
		var xPhoto:XMLLoader = new XMLLoader("image.xml");
		xPhoto.addEventListener(LoaderEvent.CHILD_COMPLETE, xmlLoaded);
		xPhoto.load();		
		trace("trace2");
		}

	private function xmlLoaded(e:LoaderEvent):void
	{
		var xData:XML = e.target.content;
		var xImgList:XMLList = new XMLList(xData.img);
		//set up maxObject
		var thumbLoader:LoaderMax = new LoaderMax( {name:"thumbLoader"} );
		thumbLoader.addEventListener(LoaderEvent.COMPLETE, thumbsLoaded);
		trace(thumbholder);
		trace("trace3");

		for (var i:int = 0; 1< xImgList.length(); i++)
		{
			var iLoad:ImageLoader = new ImageLoader(xImgList[i].@url, new ImageLoaderVars()
			.name(xImgList[i].@name)
			.width(150)
			.height(150)
			.smoothing(true)
			.container(thumbholder)
			)
			thumbLoader.append(iLoad);
			trace("trace4");
		}
		thumbLoader.load();
		trace("trace5");
	}
	private function thumbsLoaded(event:LoaderEvent):void
		{trace ("thumbs are loadin");
		trace("trace6");
		}

	override public function transitionIn():void 
	{
		super.transitionIn();
		TweenMax.to(this, 0.3, {alpha:1, onComplete:transitionInComplete});		
		trace("trace7");
		}
	override public function transitionOut():void 
	{
		super.transitionOut();
		TweenMax.to(this, 0.3, {alpha:0, onComplete:transitionOutComplete});
	}
}
}

 

 

I added a the thumbholder trace into XMLLoaded function as requested. It did not result in an output.:

trace(thhumbholder)

 

I also added the:

function thumbsLoaded(event:LoaderEvent):void{
   trace("all thumbs loaded");
}

 

It loaded the page with one holder which was originally placed on the stage by me.

 

 

To follow i also added the following:

trace(trace1) ....trace(trace[i]);

 

The output was:

 

trace1

trace2

trace7

 

 

I guess i have not represented the movieClip thumbholder on the page correctly.That at a guess is for why each xml image is not loading.

PS By the way I am not receiveing any stream errors such as # 2030, I'm sure of each files location in relation to each other is correct.

Link to comment
Share on other sites

Looks like a typo (thhumbholder) but it looks right in your code chunk

 

trace(thumbholder);

instead of

trace("trace1");

before your 1st function, if it exists it should return

[object MovieClip]

If it doesn't show you that, check your stage. Maybe got ya it switched around and needs to be thumbholder_mc instead?

 

I'm not sure about the XMLLoader activation being inside the function or that you need it, I haven't yet... I've only needed to activate loaders that aren't called in the script but in the XML and that's only been for SWFLoader, ImageLoader, etc... and I'll generally put those up under the imports.

 

Another neat thing about LoaderMax is the garbage collection. You don't have to remove event listeners if you use something like this in your BethPage function

public function BethPage()
{
 super();
 alpha = 0;
 LoaderMax.activate([xmlLoader]); //Needed??
 var xPhoto:XMLLoader = new XMLLoader("image.xml", {onChildComplete:xmlLoaded});
 xPhoto.load();      
 trace("trace2"); //Will only say trace2, nothing meaningful
}

 

Because you are never seeing "trace3" it's telling me that your xmlLoaded isn't firing. Something I've been learning is to start my functions with a trace like

trace("xmlLoader just got triggered");

for whatever the function name is. that way I know I at least got to that point.

Then moving line by line, tracing events, targets & contents, etc... I'm new to it too so that's been helping me quite a bit.

 

HTH

Karl

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