| | |
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: 227
Reputation:
Solved Threads: 18
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: 227
Reputation:
Solved Threads: 18
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: 227
Reputation:
Solved Threads: 18
0
#6 34 Days Ago
•
•
•
•
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 3.5 acrobat adobe adobeacrobat adobereader air ajax amazon api apple asp.net battery blogger blogging browsers code delete dell desktop development displayimageinsteadofflash eclipse error flash flash-develop flashlite flex flv free gaming gdata google hardware iamthwee ibm industry intel interactivemap iphone javascript kernel lexicon linspire linus linux map memory microsoft mobile moonlight multimedia nand news node nodes novell openoffice pdf photosynth php play plugins programming projectmanagement projectmanager quicktime ram rss running sandisk security seo serialization silverlight solidstatedrive sproutcore ssd storage streamingmedia swappingxmlfromflash swappingxmlnodes swf swf. tannenbaum text torvalds ukmap vb2008 video vulnerability w3c web windowsmedia xml xmlnotloading xsl zend zephyr zeroday







