Jump to content
Search Community

how to use xml-loaded variables in loaded swf?

thesixthhouse test
Moderator Tag

Recommended Posts

This one has got me stuck for quite some time now:

 

I'm using an XML-file to load up my LoaderMax queue, which is working just fine. What I would like to do is send the value of the extra variable ('category' in the XML below) in the XML file on to the loaded swf. This is my XML-file:

<?xml version="1.0" encoding="iso-8859-1"?>
<data>
<SWFLoader url="bump_worldclock.swf" load="true" noCache="true"  />
<SWFLoader url="cont_nu.swf" load="true" noCache="true" category="binnenland" />
</data>

Loading the 'cont_nu.swf' file onto the stage is no problem at all. Referencing to the value of the added variable works just fine. Sending the value of 'category' to that SWF (or fetching the value from within the SWF) does not work unfortunately. This is my code up to this point:

var mc:Object = currentLoader.content;
var cat:String = currentLoader.vars.category;
Object(root).addChild(mc);

I suspect there to be an easy solution to my problem. But not easy enough to solve with a Google search.

 

Any help would be greatly appreciated! Many thanks in advance!

 

 

 

 

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums.

 

I would suggest having the parent swf figure out the category and tell the child swf what to do.

 

data.xml:

<data>
<SWFLoader url="pass-data-child.swf"  load="true"  x="0" y="0" category="automobiles" />
</data>

 

ActionScript in parent swf:

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.*;
import flash.display.Sprite;
import flash.display.MovieClip;

LoaderMax.activate([SWFLoader]);

var queue:XMLLoader = new XMLLoader("xml/data.xml",{name:"xmlDoc", 
maxConnections:1, 
onChildComplete:imageCompleteHandler
});

queue.load();

function imageCompleteHandler(event:LoaderEvent):void
{
var loaded:ContentDisplay = event.target.content as ContentDisplay;
addChild(loaded);
//populate a text field in the child swf with the property category name
loaded.rawContent.category_txt.text = event.target.vars.category
}

child swf: contains no code, only a blank textfield called category_txt

 

 

see demo attached 

pass-data-child_cs6.zip

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