Reading Variables From SWFOBJECT and display xml content

I want to pass the state and city variable to the swf file from the swfobject and then display the content of the variable from the xml file.

SWFOBJECT
<script type=“text/javascript”>
YUE.onDOMReady(function() {var so = new SWFObject(“assets/promoKiosk.swf”,“amenities”,“628”,“600”,“8”,"#FFF" );
so.addParam(“wmode”,“transparent”);
so.addVariable(“state”, “CA”);
so.addVariable(“city”, “los angeles”);
so.write(“flashcontent”);
});
</script>

Promo XML
<?xml version=“1.0” encoding=“utf-8”?>
<offers>
<state id=“CA”>
<city id=“los angeles”>
<offer>This is the offer</offer>
</city>
<city id=“san fran”>
<offer>This is the offer</offer>
</city>
</state>
</offers>

Actionscript 2.0:
function findNode(parentNode:XMLNode,id:String){
var nodeChildren:Array = parentNode.childNodes;
var _length = nodeChildren.length;
for (var i=0; i < _length;i++){
if(nodeChildren*.attributes.id == id){
return nodeChildren*;
}
}
}
function displayNodeContents(cityNode:XMLNode){
// Having issue displaying content
}

var xml:XML = new XML();
xml.ignoreWhite = true;
xml.load(“promo.xml”);
xml.onLoad = function(success){
if(success){
var stateNode = findNode(this.firstChild,state);
var cityNode = findNode(stateNode,city);
displayNodeContents(cityNode);
}
}

You solution is done and you will find it here…
just love XML :slight_smile:

http://www.4shared.com/file/49757588/c8d38efc/swfobject_xml.html

Add more State nodes with different offer data to check it out

Thanks. Your example rocks. How do I just put the data in the first frame in a simple dynamic text box?

BTW you can use flashvars to pass vars to flash when it loads. It seems much more simpler that using swfobject.

On the embed and object tag on the html ad a new property called “flashvars” and then put your vars as if it was an URL: ?city=la&state=california

For the reading and parsing the xml I recommend the sephiroth class called xml2Object
http://www.sephiroth.it/file_detail.php?pageNum_comments=10&id=129

It’s really easy to use, and then you have you data in an object automatically. It doesn’t matter how long or complex is your xml.

In you situation…

<?xml version=“1.0” encoding=“utf-8”?>
<offers>
<state id=“CA”>
<city id=“los angeles”>
<offer>This is the offer</offer>
</city>
<city id=“san fran”>
<offer>This is the offer</offer>
</city>
</state>
</offers>

It would be something like

data_object.offers.city[0].offer.data //that would get This is the offer

or

data_object.offers.city[0].attributes.id //that would get los angeles

No more xml flash gibberish (firstChild, etc) :wink:

That may be something I will research. I was hoping to just get some help on the above example. I would like to get help on the displayOffer function to get the data into a simple dynamic text box area.

I got everything working great with a dynamic text box. Except I cannot get data to appear as html. I have render as html selected on the properties menu.

I think if you want html you need to put the text this way:

my_textfield.html = true;
my_texfield.htmlText = “there’s no <b>spoon</b>”;

I am using myText for the text field. But it will not show html.

//init TextArea component
myText.htmlText = true;
myText.wordWrap = true;
myText.multiline = true;
myText.label.condenseWhite=true;

//load css
myTextStyle = new TextField.StyleSheet();
myTextStyle.load(“promo.css”);
myText.styleSheet = myTextStyle;

Ostate// from swfobject
Ocity// from swfobject
//----------------------
var xml:XML=new XML();
xml.ignoreWhite=true;
xml.onLoad=xmlLoaded;
xml.load(“promo.xml”);
var dataArray:Array=new Array();

function xmlLoaded(success:Boolean)
{
if(success)
{
var totalNodes=xml.firstChild.childNodes.length;
for(var i=0;i<totalNodes;i++)
{
var currentNode:XMLNode=xml.firstChild.childNodes*; // state node
var StateObject:Object=new Object();
var cityNames:Array=new Array();// temp array

		// process all cities of this state
		for(var j=0;j&lt;currentNode.childNodes.length;j++)
		{
			var cityNode:XMLNode=currentNode.childNodes[j];
			var city=new Object();
			city.name=cityNode.attributes.id; // city id
			city.offer=cityNode.firstChild.firstChild; // offer
			cityNames.push(city);
		}
		
		StateObject.State=currentNode.attributes.id;
		StateObject.Cities=cityNames;
		
		//-------------Store everything-------------------
		
		dataArray.push(StateObject);
	}
}

displayOffer();

}

function displayOffer()
{
// trace(dataArray[0].Cities[0].name);
// access content like this…
for(var i=0;i<dataArray.length;i++)
{
if(dataArray*.State==Ostate)
{
var citiArray:Array=dataArray*.Cities;
for(var j=0;j<citiArray.length;j++)
{
if(citiArray[j].name==Ocity)
{
//var offer:String=citiArray[j].offer;
var offer:String=citiArray[j].offer;
//Alert.Show(offer);
[COLOR=“Red”]myText.htmlText = offer;[/COLOR]
return;
}
}
}
}
}

Can you post a bit of the xml & html you’re sending?

hope this will do…

http://www.4shared.com/file/49952939/58ee0f87/_2__swfobject_xml.html