PDA

View Full Version : display XML data


mmdguru
10-21-2009, 01:16 PM
Hi flashers,

I have an XML response that goes like this:

<vervelst>
> <vervet>
> <id>10456</id>
> <fornavn></fornavn>
> <etternavn></etternavn>
> <epost>[email protected]</epost>
> <mobil>[email protected]</mobil>
> <samtykkeepost>0</samtykkeepost>
> <samtykkekonkurranse>0</samtykkekonkurranse>
> <status>2</status>
> </vervet>
> <vervet>
> <id>10464</id>
> <fornavn>Rune</fornavn>
> <etternavn>Helge</etternavn>
> <epost>[email protected]</epost>
> <mobil>[email protected]</mobil>
> <samtykkeepost>0</samtykkeepost>
> <samtykkekonkurranse>1</samtykkekonkurranse>
> <status>1</status>
> </vervet>
> </vervelst>


With my code I can trace out what is important to me, that's the status and epost nodes!

I want to load this data into a movieclip with two textfields(status and epost) in flash. The problem is that I need to add movieclips dynamically equal to the length of my XML file. The XML can contain hundreds of <vervet> nodes! This is being added from a database through asp=)

Any ideas guys?? All help is greatly appreciated!

My Code so far:

package {

import flash.display.Sprite;
import flash.events.*;
import flash.net.*;

public class Status extends Sprite {


public var qs:QueryString = new QueryString();
public var id:int=10007;//qs.parameters.id;


public function Status() {


var scriptURL:URLRequest=new URLRequest("http://connectorretail.com/dn/fame/hentstatus.asp");
scriptURL.method=URLRequestMethod.POST;

var postVars:URLVariables = new URLVariables();
postVars.id=id;
scriptURL.data=postVars;

var scriptLoader:URLLoader = new URLLoader();
scriptLoader.addEventListener(Event.COMPLETE, scriptDoneLoading);
scriptLoader.load(scriptURL);


}


function scriptDoneLoading(evt:Event):void {

var responseXML:XML=new XML(evt.target.data);
parseData(responseXML);

}

function parseData(xmlOutput:XML):void {

trace("XML Output");
trace("------------------------");
trace(xmlOutput.vervet.epost);
trace(xmlOutput.vervet.status)

}

}
}



As you can see, I can trace the "epost" and "status"! I just need to represent this data into flash=)

mcandw
10-21-2009, 02:05 PM
Not quite sure what you're trying to accomplish.

Don't you just want to traverse the XML graph (see http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary827.html) and create a new MovieClip object for each record??

mmdguru
10-21-2009, 04:49 PM
I just want to display my xml data in flash! load the "epost" and "status" into dynamic textfields...

These textfields can be inside a movieclip. So I want to add a movieclip for each xml node.

Any ideas??

mmdguru
10-22-2009, 10:57 AM
Ive managed to create the amount of movieclips that are equal to the length of my epost node in my xml document...the moveclip is called statusMC!

I need to load the epost node inside a text field in my movieclip...

How do I do that?? Please help?

All help is greatly appreciated!!

My code:

package {

import flash.display.Sprite;
import flash.events.*;
import flash.net.*;

public class Status extends Sprite {

private var statusMC:StatusMC;
public var qs:QueryString=new QueryString ;
public var id:int=10007;//qs.parameters.id;



public function Status() {


var scriptURL:URLRequest=new URLRequest("http://connectorretail.com/dn/fame/hentstatus.asp");
scriptURL.method=URLRequestMethod.POST;

var postVars:URLVariables=new URLVariables ;
postVars.id=id;
scriptURL.data=postVars;

var scriptLoader:URLLoader=new URLLoader ;
scriptLoader.addEventListener(Event.COMPLETE,scrip tDoneLoading);
scriptLoader.load(scriptURL);


}


function scriptDoneLoading(evt:Event):void {

var responseXML:XML=new XML(evt.target.data);
parseData(responseXML);

}

function parseData(xmlOutput:XML):void {

trace("XML Output");
trace("------------------------");
trace(xmlOutput.vervet.epost);
trace(xmlOutput.vervet.status);

var epostList:XMLList=xmlOutput.vervet.epost;


for (var i:int=0; i<epostList.length(); i++) {

var epostElement:XML=epostList[i];

statusMC = new StatusMC();
statusMC.x = 40;
statusMC.y = 60+(i*50);
addChild(statusMC);

trace(epostElement);

}

}

}
}