Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Anks

XMLLoader and Gaia

Recommended Posts

Hey there!

 

So I'm new to greensock's XMLLoader as well as Gaia but what I want to do is I want to load all my assets on my page on the main class file when the page is first loading. That way the user doesnt have to wait for the items/images to load once they get onto my page. Now I have a site.xml which looks like this from gaia.

 

<?xml version="1.0" encoding="UTF-8"?>









 

and I have another XML document called port.xml that looks like this.

 

<?xml version="1.0" encoding="iso-8859-1"?> 




 

Now my main class file which loads the site.xml looks like this as of right now...

 

	public class Main extends GaiaMain
{		

	public function Main()
	{
		super();
		siteXML = "xml/site.xml";
	}
	override protected function onAddedToStage(event:Event):void
	{
		stage.align = StageAlign.TOP_LEFT;
		stage.scaleMode = StageScaleMode.NO_SCALE;
		super.onAddedToStage(event);
	}

}
}

and I currently have my port.xml being loaded on my port.as page. So when the user clicks on the link to goto the port.as it loads it there. I'm trying to figure out how I can load the port.xml basically when the site is loading for the first time but still be able to access the assets in the port.as so I can apply them on the stage.

 

Sorry for the length of the message, hopefully someone can help me out! Thanks :)

Link to comment
Share on other sites

Any help ? :(

 

To clarify a bit I need to be able to load this...

queue = new XMLLoader("xml/port.xml",{name:"xmlDoc", maxConnections:1, estimatedBytes:5000, onComplete:queueCompleteHandler, onChildComplete:imageCompleteHandler});
queue.load();

 

in my Main.as class with the other site.xml. Than I need to be able to access the data from my port.as page/class.

Link to comment
Share on other sites

Is this a Gaia question or a LoaderMax question? I'm not familiar with Gaia, so I can't really help you there. But if you're asking how to access your XMLLoader's content from somewhere else in your app, you can just use the LoaderMax.getLoader() or LoaderMax.getContent() methods to get your loader/content by name or URL from anywhere (well, except of course Flash won't let code in different SecurityDomains talk).

Link to comment
Share on other sites

it seems like you have LoaderMax set up in a useable fashion in your port.swf. glad you got that working.

 

As far communicating between classes and subloaded swfs within the Gaia framework, I really don't know enough about Gaia to know where to begin.

 

You will most likely get better support in a Gaia forum.

 

with the little that I know about gaia, it seems to make the most sense to have all your portfolio-related logic and external asset management confined to the port.swf. having port.swf depend on the parent swf loading assets that it needs prior to itself(port.swf) being loaded just feels a little awkward and at best a bit troublesome to implement and test. just my 2 cents.

 

again, I'm no expert, perhaps it has been done before.

Link to comment
Share on other sites

Hmm... its not so much of a Gaia question but more of an OOP question. Being able to use XMLLoader and LoaderMax between two class files. Never been very good at that /facepalm. Being able to access the the XMLLoader object I created in the main class, in my port.as class. I'm going to take a look at the LoaderMax.getContent and getLoader methods to see if I can figure it out.

 

I know as of right now it is loading the xml document. Just its a matter of telling port.as to now go into that xml document and grab that information and assign them to the specific display objects.

Link to comment
Share on other sites

Just want to make sure im on the right page here.

 

So I've taken a look at the LoaderMax.getContent() method and I'm trying to grab the first image now.

 

My XML looks like this still:

<?xml version="1.0" encoding="iso-8859-1"?> 



 

I've created an xml loader in my main class and have it being loaded.. So when the app runs it should load the xml.

public var queue:XMLLoader;

	public function Main()
	{
		super();
		siteXML = "xml/site.xml";

		queue = new XMLLoader("xml/port.xml",{name:"xmlDoc", maxConnections:1, estimatedBytes:5000});
		queue.load();

	}

 

Now on my port.as page when the user gets sent to this page I want to grab the files from the port.xml document loaded with var queue.

 

I've made an init() function and have this there currently...

private function init()
	{
		var image:ImageLoader = queue.getContent("anaImage");
		trace(image);
	}

 

It isn't working, its throwing the "access a property or method of null object ref error" so I want to know how would I access those images?

Link to comment
Share on other sites

Hi anks,

 

I'm on the same page as far as the "oop-troubles" go so my ability to help is limited.

i just did a few tests, and as GreenSock mentioned your LoaderMax object is accessible from anywhere in your app

try these in your init()

 

var image:ContentDisplay = LoaderMax.getContent("anaImage");
addChild(image);

 

or to just get a reference to the loader and not the content

 

var image:ImageLoader = LoaderMax.getLoader("anaImage");
trace(image);

 

 

 

 

when you export this swf it will throw a run time error, but should work when the parent/main swf loads it.

 

also make sure port.as has

 

import com.greensock.loading.*

Link to comment
Share on other sites

Thanks so much carl. I was on a similar :)

 

Umm I have a question though. Is it supposed to be tracing "null" when I do trace(image);?

 

Also do you know if there is there a way I can load the node @name? so that I can add multiple images instead of telling it to load each image by its given name?

Link to comment
Share on other sites

no that trace should give you

 

"ImageLoader anaImage imgs/port/ana.png"

 

that is what you get when you trace a loader

 

type, name, url

 

--------

 

Also do you know if there is there a way I can load the node @name? so that I can add multiple images instead of telling it to load each image by its given name

 

once you have access to the main LoaderMax you should be able to loop through all the child loaders and access what ever info you want. so yes you could get the content of all the ImageLoaders in your LoaderMax and do an addChild() with the content of all those loaders.

 

you have to get part one right and access the LoaderMax in the document class.

 

when you put

 

private function init()
     {
     var image:ContentDisplay = LoaderMax.getContent("anaImage");
     addChild(image);

trace("image " + image);
trace("numChildren " + LoaderMax.getLoader("xmlDoc").numChildren);
     }

 

inside port.as and then load port.swf into your main swf... what happens?

 

are you sure the XMLLoader has fully loaded before you load port.swf?

Link to comment
Share on other sites

This will always return null:

var image:ImageLoader = LoaderMax.getContent("anaImage");

because LoaderMax.getContent() returns the CONTENT, not the LOADER. So in your case, you were casting the ContentDisplay as an ImageLoader so Flash makes it null.

 

Carl had the correct technique:

 

//to get the content (ContentDisplay object in this case):
var image:ContentDisplay = LoaderMax.getContent("anaImage");

//to get the ImageLoader instance:
var image:ImageLoader = LoaderMax.getLoader("anaImage");

 

If you're still getting null, that probably just means that your XML hasn't finished loading. And did you make sure to activate() the ImageLoader before loading your XML? If not, XMLLoader won't recognize the nodes inside the XML. Just do LoaderMax.activate([imageLoader]); once before you load your XML and you'll be golden.

 

If your XML hasn't finished loading yet (when you're trying to access the parsed loaders), you can check that and then add event listeners so that you're notified when it is done, like:

 

var xmlLoader:XMLLoader = LoaderMax.getLoader("xmlDoc");
if (xmlLoader.status == LoaderStatus.COMPLETED) {
   doStuffWithImage(null);
} else {
   xmlLoader.addEventListener(LoaderEvent.COMPLETE, doStuffWithImage);
}

function doStuffWithImage(event:LoaderEvent):void {
   var imageLoader:ImageLoader = LoaderMax.getLoader("anaImage");
   //do other stuff...
}

 

Does that clear things up?

Link to comment
Share on other sites

Awesome! Can't thank you both enough for the help and patience with me here! :)

 

I now I have one successful image being added from my XML document to the stage!

 

Now the next step I have to do is add all the pictures to the stage from the XML document.

 

Carl, about using numChildren to achieve this....

trace("numChildren " + LoaderMax.getLoader("xmlDoc").numChildren);

 

I've added this trace to my code but it seems to be throwing an error "Property numChildren not found on com.greensock.loading.XMLLoader and there is no default value."? I'm assuming this is supposed to trace the number of imageloaders I have in my xml document?

Link to comment
Share on other sites

sorry about that XMLLoader doesn't have a numChildren property, but it does have a getChildren() method which returns an array of all the loaders.

 

 

this returns an array of all the loaders

LoaderMax.getLoader("xmlDoc").getChildren()

 

so you could do:

 

var loadersArray:Array = LoaderMax.getLoader("xmlDoc").getChildren()

 

then you could access each loader's content with

 

loadersArray[0].content

loadersArray[1].content

 

etc

Link to comment
Share on other sites

Awesome! thank you so much for your help! :D

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