dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [RESOLVED] loading xml through httpservice into arraycollection

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    68

    [RESOLVED] loading xml through httpservice into arraycollection

    Hi,

    i have to load an xml file :
    ?xml version="1.0" encoding="utf-8"?>
    <videoChoices>
    <film>
    <src>01-introductie.jpg</src>
    <title>Introduction</title>
    <videoNr>01-introduction</videoNr>
    <txt>Medical Director\nTime - 21:44 min</txt>
    </film>
    <film>
    <src>02-introductie.jpg</src>
    <title>Introduction2</title>
    <videoNr>02-introduction</videoNr>
    <txt>Medical Director\nTime - 20:11 min</txt>
    </film>
    </videoChoices>
    i do this with an httpservice :

    <mx:HTTPService id="get_videoChoiceInfo" url="assets/ignore/VideoChoice.xml" resultFormat="array" useProxy="false"
    method="GET" result="handleVideoInfo(event);" />
    I do a send of the service when the components that contains all this creation is complete.

    [Bindable] private var VideoKeuze:ArrayCollection=new ArrayCollection();
    to instantiate the arraycollection

    private function handleVideoInfo(event:ResultEvent):void{
    VideoKeuze=ArrayCollection(event.result);
    }
    to get the whole xml into the arraycollection. The aaraycollection is to be used for the dataProvider of a repeater.

    I tried a bunch off things, but i cant get the xml read into the arraycollection.

    I seem to not understand this process.

    Some help pls.

    B
    Last edited by banshee007; 04-26-2007 at 10:41 AM.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    This is Flex 2. I move the thread to the new forum.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    I added a couple of items to your xml and replaced the newline (\n) with entities so I can read it inline.

    ?xml version="1.0" encoding="utf-8"?>
    <videoChoices>
    <film>
    <src>01-introductie.jpg</src>
    <title>Introduction</title>
    <videoNr>01-introduction</videoNr>
    <txt>Medical Director&amp;#013;Time - 21:44 min</txt>
    </film>
    <film>
    <src>02-introductie.jpg</src>
    <title>Introduction2</title>
    <videoNr>02-introduction</videoNr>
    <txt>Medical Director&amp;#013;Time - 20:11 min</txt>
    </film>
    <film>
    <src>03-introductie.jpg</src>
    <title>Introduction3</title>
    <videoNr>03-introduction</videoNr>
    <txt>Medical Director&amp;#013;Time - 21:44 min</txt>
    </film>
    <film>
    <src>04-introductie.jpg</src>
    <title>Introduction4</title>
    <videoNr>04-introduction</videoNr>
    <txt>Medical Director&amp;#013;Time - 20:11 min</txt>
    </film>
    </videoChoices>


    Using this handler:


    private function handleVideoInfo(event:ResultEvent):void {
    VideoKeuze = event.result.videoChoices.film;
    }


    And this repeater:

    <mx:VBox width="500" height="500" horizontalCenter="0" top="20" backgroundColor="#c0c0c0">
    <mx:Repeater id="rp" dataProvider="{VideoKeuze}">
    <mx:Canvas width="100%" height="120">
    <mx:Label text="{rp.currentItem.src}" left="10" y="10"/>
    <mx:Label text="{rp.currentItem.title}" y="30" left="10"/>
    <mx:Label text="{rp.currentItem.videoNr}" y="50" left="10"/>
    <mx:Text htmlText="{rp.currentItem.txt}" width="200" height="50" y="70" x="10"/>
    </mx:Canvas>
    </mx:Repeater>
    </mx:VBox>


    What you actually populate with inside your repeater is up to you. I simply wanted to show all item values entering and also your newline being recognized inline

  4. #4
    Member
    Join Date
    Nov 2005
    Posts
    68
    i get the following error now :
    Error: Unknown Property: 'videoChoices'.
    The actual code is :

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="560" height="460" xmlns:ns1="components.*" creationComplete="sendService();">
    	
    	<mx:Script>
    		<![CDATA[
    			import mx.rpc.events.ResultEvent;
    			import mx.collections.ArrayCollection;
    			import mx.effects.easing.Exponential;
    			private var video:String;
    			[Bindable] private var symposiumVideoKeuze:ArrayCollection=new ArrayCollection();
    
    			
    			private function sendService():void{
    				get_videoChoiceInfo.send();
    			}
    			
    			private function callVideo(naam:String,title:String):void{
    				video=naam;
    				mainVideoSlides.setVideo(video);
    				mainVideoSlides.videoTitle.text=title;
    			}
    			
    			private function handleSymposiumVideoInfo(event:ResultEvent):void{
    				//symposiumVideoKeuze=ArrayCollection(event.result);
    				symposiumVideoKeuze = event.result.videoChoices.film
    			}
    		]]>
    	</mx:Script>
    	
    	<mx:HTTPService id="get_videoChoiceInfo" url="assets/ignore/symposiumVideoChoice.xml" resultFormat="array" useProxy="false"
    	method="GET" result="handleSymposiumVideoInfo(event);" />
    	
    	<mx:Move id="moveIt" xFrom="130" xTo="0" duration="1500" easingFunction="{Exponential.easeOut}"/>
    
    	<mx:Canvas id="videoKeuze" width="100%" height="460" visible="false" showEffect="{moveIt}" styleName="achtergrondKleur" x="0" y="0" horizontalScrollPolicy="off">
    		<mx:Canvas backgroundColor="#FFFFFF" alpha="0.30" x="0" y="0" width="100%" height="40"  >
    			<mx:Text x="226" y="13" text="Symposium" fontWeight="bold" fontSize="14"/>
    		</mx:Canvas>
    		<mx:Canvas width="560" height="100%" y="40" horizontalScrollPolicy="off">
    		<mx:VBox width="100%" verticalGap="2" horizontalScrollPolicy="off">
    			<mx:Repeater id="rptrSymposium" dataProvider="{symposiumVideoKeuze}">
    				<mx:Canvas width="100%" height="140" horizontalScrollPolicy="off" verticalScrollPolicy="off">
    					<mx:Image source="{String(rptrSymposium.currentItem.src)}" width="150" x="15" y="5" 
    						click="callVideo(event.currentTarget.getRepeaterItem().videoNr,event.currentTarget.getRepeaterItem().title)" buttonMode="true"/>
    					<mx:LinkButton y="5" x="170" label="{rptrSymposium.currentItem.title}" 
    						click="callVideo(event.currentTarget.getRepeaterItem().videoNr,event.currentTarget.getRepeaterItem().title)"/>
    					<mx:Text y="30" x="180" text="{rptrSymposium.currentItem.txt}"/>
    				</mx:Canvas>
    			</mx:Repeater>
    		</mx:VBox>
    		</mx:Canvas>
    	</mx:Canvas> 
    	<mx:SWFLoader source="assets/schuifraam.swf" showBusyCursor="true" id="SchuifraamSymposiumInfo" 
    		 width="560" height="460" x="0" y="0" complete="videoKeuze.visible=true"/>
    							 
    </mx:Canvas>
    Last edited by banshee007; 04-26-2007 at 01:12 PM.

  5. #5
    Member
    Join Date
    Nov 2005
    Posts
    68
    I'm a bit confused here : the httpservice gives back an array.
    In the result handler the ResultEvent contains an object, and in that object is the array. If this is correct, why can't the array be casted to an ArrayCollection ?

  6. #6
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    First off:

    The actual code is

    Why not post the actual code to begin with? It wastes our time making multiple movies because users decide to give us partial or incomplete benefit of the doubt.

    Second...leave the HTTPService at it's default (object). You asked for an example and I've given one that worked and am about to place a second that works. If you start getting creative and it breaks...it's on you.

    Third:

    There are things referenced in your component (this is a component you've pasted and I do not have benefit of either all the assets this routine requires nor it's images nor it's main stage coding (mxml)). That said...I've simply sliced out what I cannot use (mainVideoSlides and videoKeuze and I've also yanked out the SWFLoader because I don't have your movie and it's just in my way) and will use two textfields to visually show the callVideo function...does in fact ....get sent the variables.


    PHP Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="560" height="460" xmlns:ns1="components.*" creationComplete="sendService();">
        
            <mx:HTTPService id="get_videoChoiceInfo"
            url="assets/ignore/symposiumVideoChoice.xml"
            result="handleSymposiumVideoInfo(event)"/>

        <mx:Script>
            <![CDATA[
            
               
                import mx.collections.ArrayCollection;
                import mx.rpc.events.ResultEvent;
                import mx.effects.easing.Exponential;
                
               [Bindable]
                private var video:String;
                
                [Bindable]
                private var selectedItem:Object;
                
                
                
                [Bindable]
                private var symposiumVideoKeuze:ArrayCollection;
                
                private function sendService():void{
                    get_videoChoiceInfo.send();
                }
                
                private function handleSymposiumVideoInfo(event:ResultEvent):void {
                    symposiumVideoKeuze = event.result.videoChoices.film;
                  
                }
      
               private function callVideo(naam:String,title:String):void{
                    video=naam;
                    //these are visual for the stage to show the function recieved ok
                    aa.text=video;
                    bb.text=title;
                    
                    //these are missing...same with "videoKeuze"
                    //mainVideoSlides.setVideo(video);
                    //mainVideoSlides.videoTitle.text=title;
                }
          
                 
                
            ]]>
        </mx:Script>

          

              <mx:VBox width="500" height="500" horizontalCenter="-135" top="24" backgroundColor="#c0c0c0">
               <mx:Repeater id="rptrSymposium" dataProvider="{symposiumVideoKeuze}">
                <mx:Canvas width="100%" height="120">
                    <mx:Image source="{rptrSymposium.currentItem.src}" width="150" x="15" y="5" buttonMode="true"/>
              <mx:LinkButton y="5" x="170" label="{rptrSymposium.currentItem.title}" 
                            click="callVideo(event.currentTarget.getRepeaterItem().videoNr,event.currentTarget.getRepeaterItem().title)" textAlign="left"/>
                        <mx:Text y="35" x="175" htmlText="{rptrSymposium.currentItem.txt}" width="257" height="45"/>
                </mx:Canvas>    
               </mx:Repeater>  
              </mx:VBox>
              
        <mx:TextArea x="640" y="75" width="227" id="aa" height="20"/>
        <mx:TextArea x="640" y="133" width="227" id="bb" height="20"/>
        <mx:Label x="640" y="10" text="Values passed to callVideo function" width="227" textAlign="center" fontWeight="bold"/>
        <mx:Label x="640" y="58" text="value of &quot;naam&quot;" width="227" textAlign="left"/>
        <mx:Label x="640" y="116" text="value of &quot;title&quot;" width="227" textAlign="left"/>
            
                                   
    </mx:Canvas>

    Like I said....I'm using two textfields onstage to show the variables passed to the function. I will leave it to you to adapt to your actual movie. Here it is working:


    http://www.flex-fanatic.com/examples...e/banshee.html


    I'm going to let another mod deal with any additional coding needed for this movie. You asked about repeaters...two were shown....obligation met.

  7. #7
    Member
    Join Date
    Nov 2005
    Posts
    68
    Hi Chris,

    i'm sorry. I thought it was requested in the forums and normal behaviour to post only the least bit of code that is needed to handle the problem.
    The second post with more of my code i made because i thougth maybe there is someting wrong with the code i didn't post yet. I tried to take out the bits i thougth really didn't matter (there is a state change), but i forgot to remove the code u commented out and the swfloader.

    I see that ur code works fine. I now removed the "resultformat=array" and mine also works. I tried this before, but not in combination with "symposiumVideoKeuze = event.result.videoChoices.film;"

    Thans for ur help, i really appreciate this a lot.

    grt,

    B

  8. #8
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    I bark a lot..but I mean well. Glad it all worked out...it's only the ones with dynamic assets that are hard to emulate because I have to make fake everything

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center