9 Replies Latest reply on Aug 23, 2010 12:01 PM by Devtron

    how do i put a HTTPService result into an SkinnableDataContainer

    Zombiecook KochtVorWut Level 1

      Hello,

      how do i can put a HTTPService result that looks like this:

      <user>
           <username>user</username>
           <email>user@email.com</username>
      </user>
      <user>
           <usernam... and so on
      

       

      into an SkinnableDataContainer or an ArrayList ?

       

          <s:SkinnableDataContainer dataProvider="{UserArraylist}" itemRenderer="Skins.UserItemRenderer" >
              <s:layout>
                  <s:VerticalLayout gap="1" />
              </s:layout>
          </s:SkinnableDataContainer>
      

       

       

      I have tried to loop the content that comes within the result and put it into an ArrayList but that failed.

       

      Thank you,

      Zombiecook

        • 1. Re: how do i put a HTTPService result into an SkinnableDataContainer
          ozDiGennaro Level 1

          It's not a hard problem to implement in Actionscript.  You get the result from the HTTP service call.  Either as an object or as XML.  In either case,

          you can walk the hierarchy looking for the elements that interest you.  Then you can directly assign the display elements with values.

          If you want sample code, I can supply it.

           

          So, actually, you could help us by saying what you want it to look like.

           

          Oz - 4dtext tools

          • 2. Re: how do i put a HTTPService result into an SkinnableDataContainer
            Zombiecook KochtVorWut Level 1

            Actually i want it to look like an list and like this : http://www.adobe.com/devnet/flex/videotraining/exercises/ex4_02/fig04.jpg

            i know how to access the xml in the resulthandler but when there are more then one user item then i can not display it.

             

            For example i access normally event.result.users.user.name and have the name but when there is a second user this dont work.

            <users>
                 <user>
                      <name>user1</name>
                      <email>user1@email.com</email>
                 </user>
                 <user>
                      <name>user2</name>
                      <email>user2@email.com</email>
                 </user>
            </users>
            

            Best would be when i can put this into an arraycollection or an Object but i have no clue how to handle a Object .

             

            I hope it showed a little bit better what i want to do.

            And if you have a sample code i would be happy if you can supply it.

            greetings

            Zombiecook

             

            ps. sry for my bad english.

             

            EDIT:

            here is what i want to have:

                    <s:ArrayList id="ArrayList1">
                        <fx:Object username="User1" email="User1@email.com" />
                        <fx:Object username="User2" email="User2@email.com" />
                        <fx:Object username="User3" email="User3@email.com" />
                        <fx:Object username="User4" email="User4@email.com" />
                        <fx:Object username="User5" email="User5@email.com" />
                    </s:ArrayList>
            

            I want to put the stuff that cames from my php file (HTTPService - result) to generate for each entry a own Object and put all the generated Objects into an ArrayList. I know how to add an Item but how to add Items of which i dont know the quatity and which come in the way of an XML list?

            • 3. Re: how do i put a HTTPService result into an SkinnableDataContainer
              Balakrishnan V Level 3

              You could try this.

               

              var resultArrayCollection:ArrayCollection = event.result.users.user as ArrayCollection.

               

              resultArrayCollection.getItemAt(i) returns the object at index " i " in the array collection.

               

              Is there any specific reason why you want to use an ArrayList, because an ArrayCollection can also be bound as dataProvider.

               

              If you want only an ArrayList, then you can use this

               

              var resultArrayList:ArrayList=new ArrayList()

              resultArrayList.addAll(IList(resultArrayCollection))

               

              Hope this helps,

               

              Balakrishnan V

              1 person found this helpful
              • 4. Re: how do i put a HTTPService result into an SkinnableDataContainer
                Zombiecook KochtVorWut Level 1

                thank you,

                i tried to get it work but it dont worked out for me : (iam trying to upload a sample file)

                 

                <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                               xmlns:s="library://ns.adobe.com/flex/spark" 
                               xmlns:mx="library://ns.adobe.com/flex/mx" 
                               initialize="init(event)">
                
                    <fx:Declarations>
                        <s:HTTPService result="httpservice1_resultHandler(event)" id="simpleHttpService"
                                       url="http://localhost/sandbox/test.php" method="GET">    
                        </s:HTTPService>
                    </fx:Declarations>
                    <fx:Script>
                        <![CDATA[
                            import mx.events.FlexEvent;
                            import mx.rpc.events.ResultEvent;
                            import mx.collections.*;
                            
                            [Bindable] protected var resultArrayCollection:ArrayCollection = new ArrayCollection;
                
                            
                            protected function init(event:FlexEvent):void {
                                simpleHttpService.send();
                            }
                            
                            protected function httpservice1_resultHandler(event:ResultEvent):void {
                                //OutPut.text += "username: " + event.result.user.username + "  email: " + event.result.user.email;
                                //OutPut.text += "\n" + event.result.users.user;
                                resultArrayCollection = event.result.users.user;
                                
                            }
                
                        ]]>
                    </fx:Script>
                
                    <s:SkinnableDataContainer dataProvider="{resultArrayCollection}" itemRenderer="Skins.UserItemRenderer" verticalCenter="0" horizontalCenter="0" >
                        <s:layout>
                            <s:VerticalLayout gap="1" />
                        </s:layout>
                        
                    </s:SkinnableDataContainer>
                </s:Application>
                

                 

                The itemRenderer :

                    <mx:HBox horizontalGap="1" backgroundColor="#ff0000" backgroundAlpha="0.3">
                        <s:Label text="{data.identifer}"/>
                        <s:Label text="{data.username}"/>
                        <s:Label text="{data.email}"/>
                    </mx:HBox>
                

                And again the result looks exactly like this:

                <users><user><identifer>1</identifer><username>Admin</username><email>contact_us@email.com</email></user><user><identifer>2</identifer><username>user</username><email>user@email.com</email></user></users>

                 

                 

                I have found this : http://help.adobe.com/de_DE/Flex/4.0/FlexTutorials/WS4bebcd66a74275c3-177557f11232f6db7fc- 8000.html
                And when someone know a way to work with an output like this, i would be happy to know how :

                array(999) { 
                [0]=> 
                    object(user)#4 (6) { 
                        ["identifer"]=> 
                        string(1) "1" 
                        ["username"]=> 
                        string(2) "admin" 
                        ["email"]=> 
                        string(3) "contact_us@email.com" 
                    } 
                [1]=> 
                    object(user)#5 (6) { 
                        ["identifer"]=> 
                        string(1) "2" 
                        ["username"]=> 
                        string(2) "user" 
                        ["email"]=> 
                        string(3) "user@email.com" 
                    } 
                [2]=> 
                    object(user)#6 (6) { 
                        ["identifer"]=> 
                . . .
                • 5. Re: how do i put a HTTPService result into an SkinnableDataContainer
                  Balakrishnan V Level 3

                  <?xml version="1.0" encoding="utf-8"?>

                  <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                     xmlns:s="library://ns.adobe.com/flex/spark"

                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">

                  <fx:Script>

                  <![CDATA[

                  import mx.collections.ArrayCollection;

                  import mx.collections.ArrayList;

                  import mx.collections.IList;

                  import mx.events.FlexEvent;

                  import mx.rpc.events.ResultEvent;

                   

                  [Bindable]private var myArrayList:ArrayList=new ArrayList();

                   

                  protected function myService_resultHandler(event:ResultEvent):void

                  {

                  // TODO Auto-generated method stub

                  myArrayList.addAll(IList(event.result.catalog.book))

                  }

                  protected function application1_creationCompleteHandler(event:FlexEvent):void

                  {

                  // TODO Auto-generated method stub

                  myService.send()

                  }

                   

                  ]]>

                  </fx:Script>

                  <fx:Declarations>

                  <s:HTTPService id="myService" url="xml/catalog.xml" result="myService_resultHandler(event)"/>

                  </fx:Declarations>

                  <s:List id="myList" height="100%" width="100%" dataProvider="{myArrayList}">

                  <s:itemRenderer>

                  <fx:Component>

                  <s:ItemRenderer>

                  <s:states>

                  <s:State name="normal"/>

                  </s:states>

                  <s:BorderContainer width="100%">

                  <s:layout>

                  <s:VerticalLayout/>

                  </s:layout>

                  <s:Label text="{data.username}"/>

                  <s:Label text="{data.email}"/>

                  </s:BorderContainer>

                  </s:ItemRenderer>

                  </fx:Component>

                  </s:itemRenderer>

                  </s:List>

                  </s:Application>

                  • 6. Re: how do i put a HTTPService result into an SkinnableDataContainer
                    Zombiecook KochtVorWut Level 1

                    Thank you so much !
                    The only question i have is: did the List component always have an white background ?

                    • 7. Re: how do i put a HTTPService result into an SkinnableDataContainer
                      Balakrishnan V Level 3

                      Yeah

                       

                      If you want the exact effect as that given in that flex in a week training,

                      you should set the backgroundColor of the BorderContainer as grey or

                      whatever color you choose.

                      1 person found this helpful
                      • 8. Re: how do i put a HTTPService result into an SkinnableDataContainer
                        Zombiecook KochtVorWut Level 1

                        yeah, sry the question was needless. I have made an skin for the List. And again thank you very much

                        • 9. Re: how do i put a HTTPService result into an SkinnableDataContainer
                          Devtron Level 3

                          Thank you for providing an example with dynamic data.

                           

                          It is very frustrating that all over the internet (and in the books), that all ArrayLists generally are static and hardcoded.

                           

                          In a real world environment, there is rarely a need or desire to use static arrays.


                          I have found this to be incredibly frustrating and limiting to my development time with FLEX.

                           

                          I would much rather see examples like this, where data is provided through the Web, and not hardcoded for a small example. Good job.