| | |
Actionscript 3 XML help
Please support our Graphics and Multimedia advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2008
Posts: 231
Reputation:
Solved Threads: 19
Hi, I am trying to retrieve the contents of my XML file and use the variables later on in the script;
I have the following actionscript code
and the following is the contents of data.xml
I'm trying to get the contents of the
Thanx,
Sam
I have the following actionscript code
Graphics and Multimedia Syntax (Toggle Plain Text)
// Get XML Vars var xml:XML; var urlLoader = new URLLoader(); var songdataurl:String = '0'; urlLoader.addEventListener(Event.COMPLETE,onXMLLoaded); urlLoader.load(new URLRequest("data.xml")); function onXMLLoaded(e:Event):void{ xml = new XML(e.target.data); GetSongData(); } function GetSongData():void{ songdataurl = xml..song[0]; } trace(songdataurl); //Use songdataurl in script
and the following is the contents of data.xml
xml Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="UTF-8"?> <songs> <song title="A Song" artist="Joe Blogs" album="An Album">/getsong/?ID=12345&Hash=12345678&IP=0.0.0.0</song> </songs>
<song></song> tag and use it later on in my script.Thanx,
Sam
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
•
•
Join Date: May 2008
Posts: 231
Reputation:
Solved Threads: 19
0
#3 Oct 18th, 2009
This is the first time I have ever used AS3, I just want the variable to be available further on in the script (outside onXMLLoaded function)
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
Mr samarudge,
Your code is written in a right way!, and It works. But whats the problem is before reading your xml, the trace statement is executed once. You should give time to load your xml and after that only have to use trace statement. Thats the problem!.
you can test this by using the below code.
Hope this helps!
Your code is written in a right way!, and It works. But whats the problem is before reading your xml, the trace statement is executed once. You should give time to load your xml and after that only have to use trace statement. Thats the problem!.
you can test this by using the below code.
Graphics and Multimedia Syntax (Toggle Plain Text)
var songdataurl:String; var xml:XML; var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener(Event.COMPLETE,onXMLLoaded); urlLoader.load(new URLRequest("data.xml")); function onXMLLoaded(e:Event):void{ xml = new XML(e.target.data); GetSongData(); } function GetSongData():void{ songdataurl = xml..song[0]; } var timer:Timer=new Timer(500); timer.addEventListener(TimerEvent.TIMER,process); timer.start(); function process(e:TimerEvent):void { trace(songdataurl); }
Hope this helps!
•
•
Join Date: May 2008
Posts: 231
Reputation:
Solved Threads: 19
0
#6 Oct 19th, 2009
•
•
•
•
Mr samarudge,
Your code is written in a right way!, and It works. But whats the problem is before reading your xml, the trace statement is executed once. You should give time to load your xml and after that only have to use trace statement. Thats the problem!.
you can test this by using the below code.
Graphics and Multimedia Syntax (Toggle Plain Text)
var songdataurl:String; var xml:XML; var urlLoader:URLLoader = new URLLoader(); urlLoader.addEventListener(Event.COMPLETE,onXMLLoaded); urlLoader.load(new URLRequest("data.xml")); function onXMLLoaded(e:Event):void{ xml = new XML(e.target.data); GetSongData(); } function GetSongData():void{ songdataurl = xml..song[0]; } var timer:Timer=new Timer(500); timer.addEventListener(TimerEvent.TIMER,process); timer.start(); function process(e:TimerEvent):void { trace(songdataurl); }
Hope this helps!
Thanx, marked solved and rep added
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
![]() |
Similar Threads
- Flash ActionScript Game Developers Required. (Software Development Job Offers)
- Designing a Flash Video Player (Graphics and Multimedia)
- ActionScript XML and a good XML Editor (RSS, Web Services and SOAP)
- Flash News on the Website (IT Professionals' Lounge)
- R/GA looking for Flash Dev's (Web Development Job Offers)
Other Threads in the Graphics and Multimedia Forum
- Previous Thread: Help me please
- Next Thread: Display products
| Thread Tools | Search this Thread |
.net acrobat actionscript3 adobe adobeacrobat amf api apple asp.net battery blogger blogging browsers cloud code delete dell development directshow dojofoundation eclipse elasticcomputecloud elearning firefox flash flashlite flex flipbook flv fotb gdata google harddrive hardware html iamthwee ibm image imflash industry intel interactivemap iphone kernel laptop lexicon linus linux macbook memory micron microsoft moonlight multimedia nand news node openoffice optimisation pcm pdf photosynth php play plugins programming projectmanagement quicktime ram rss running search security silverlight software solidstatedrive ssd standards streamingmedia swappingxmlfromflash swf swf. text torvalds transform txttoxmlconverter vb2008 video vulnerability w3c warning web website windowsmedia xml xmlnotloading xmlonserver xsl zend zeroday







