Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2008
    Posts
    104
    Thanks
    4
    Thanked 14 Times in 14 Posts

    n00b question - XML import

    Hi guys,

    Sorry to be a pain - trying to get my head round XML import - I've written as best I can a script that simply imports an XML file onto a datagrid (in very similar fashion to the vid tutorial on Adobe's website) - here is the MXML:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundAlpha="0"
    	initialize = "playlist.send()">
    	
    	<mx:Script>
    		<![CDATA[
    			import mx.collections.ArrayCollection;
    			import mx.rpc.events.ResultEvent;
    			
    			
    			[Bindable]
    			private var plist:ArrayCollection;
    			
    			private function resultHandler(event:ResultEvent) :void {
    				
    				plist = event.result.playlist.tracklist;
    				
    			}
    			
    		]]>
    	</mx:Script>
    	<mx:HBox paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10" horizontalGap="20">
    		<mx:Image/>
    		
    	</mx:HBox>
    	
    	<mx:HTTPService id="playlist" url="playlist.xml" result="resultHandler(event)"/>
    	
    	<mx:DataGrid dataProvider="{plist}" width="100%" height="100%" />
    	
    </mx:Application>
    for some reason I cannot fathom, when I debug this script with a breakpoint at the end of resultHandler(), although event is fully populated with all the right info, plist remains stubbornly "null". I'm sure I'm missing something, but I've no idea what! Anyone any ideas why plist isn't being assigned?

    Here is a sample of the XML data:

    Code:
    <playlist version="1" xmlns="http://xspf.org/ns/0/">
    	<title>Edward Caine Pieces</title>
    	<info></info>
    	<annotation></annotation>
    	<trackList>
    	
    		<track>
    			<creator>Tous les matin du monde</creator>
    			<title>Ossian Ensemble, Late Music Concert Series, 7/11/09</title>
    			<location>/mp3s/matin.mp3</location>
    			<image>images/ossia.jpg</image>
    			<info></info>
    			<album>Late Music Concert Series 09</album>
    		</track>
    	</trackList>
    </playlist>
    Any help would be greatly appreciated!

    Best
    Edd
    Last edited by eddjc; 02-25-2010 at 12:28 AM. Reason: mistake in code

  • #2
    Regular Coder
    Join Date
    Aug 2008
    Posts
    104
    Thanks
    4
    Thanked 14 Times in 14 Posts
    Hello All,

    Well as usual, astonishingly, I worked out what was wrong within 5 seconds of posting (LOL - 30 mins scratching your head, 2 mins typing up to forum, then 5 seconds to go "Ugh", slap your forehead and then logon to the forums to apologise)

    Basically, I'd not clocked that <trackList></trackList> in my XML was spelt with a capital L. Also my code was slightly wrong - the ArrayCollection was event.result.playlist.trackList.track but that was a fault in my post - that was the array I expected.

    Doh! Thank you for your time reading though if you did! Sorry for the rookie mistake...

    Cheers
    Edd


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •