Jump to content
GreenSock

icekomo

using XML data from the loaderMax file.

Recommended Posts

Hello, I would like to start out by saying that I'm a flash designer and not a developer so the questions I have may seem simple. This is the basics of what I'm trying to do.

I have a preloader file that I am using loaderMax on, I have fla file that contains all my assests for the site and I have a .as file that I am using to control all of those assets. I have my preloader file loading in the swf file as well as the xml file. This all is working great, as the wf file shows up and works, and I am able to trace the xml file, so I know that works too. What I can't figure out is how to populate my textFields in my .as file with the xml data i loaded from the prelaoder.

 

Here is my preloader code:

 

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;

//create a LoaderMax named "mainQueue" and set up onProgress, onComplete and onError listeners
var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});

//append several loaders
queue.append( new XMLLoader("xml/testMenus.xml", {name:"myXML", estimatedBytes:1200}) );
queue.append( new SWFLoader("test.swf", {name:"contentClip", estimatedBytes:270000, container:this, visible:true}) );
//start loading
queue.load();
//xmlLoader.load();
function progressHandler(event:LoaderEvent):void {
   trace("progress: " + event.target.progress);
}
function completeHandler(event:LoaderEvent):void {
   trace(event.target + " is complete!");
var data_xml:XML = LoaderMax.getContent("myXML");
   trace(data_xml);	
}
function errorHandler(event:LoaderEvent):void {
   trace("error occured with " + event.target + ": " + event.text);
}

 

My as code that doesn't work because it can't fine the data_xml var used in the preloader.

 

brunchMenu.Menu_mc.content_mc.menuTxt.htmlText = String(data_xml.Brunch).replace("\n", "");

 

Thank you in advance for looking at this.

Link to comment
Share on other sites

Oh, if you're trying to access your data_xml variable OUTSIDE the completeHandler() function, then don't declare it as a local variable inside that function. Local variables are deleted as soon as the parent function finishes running.

 

Just declare it outside, like:

 

var data_xml:XML;
function completeHandler(event:LoaderEvent):void {
   trace(event.target + " is complete!");
   data_xml = LoaderMax.getContent("myXML");
   trace(data_xml);   
}

Link to comment
Share on other sites

Thanks but that still didn't fix the problem, I can declare the var out side of the function but now do I get the .as file to see that var in my preloader file?

So i load the xml and the swf file into the preloader file, and that swf file has an external .as file where i keep all my code, so I just need to know how to link that .as file to my preloader file so they can share vars.

Link to comment
Share on other sites

Why not just load the XML into the SWF directly?

 

Anyway, you could do something like this in the child swf: myVariable = MovieClip(this.parent.parent).data_xml;

 

Or have a setXML() method that accepts an XML parameter in the child, and then call it from the parent like myLoader.rawContent.setXML(data_xml);

 

(I think the latter would be better frankly).

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