10 Replies Latest reply on Aug 12, 2010 11:04 PM by actstorm

    Contact list with xml

    actstorm

      Hi,

       

      I working with an IM client in Flex 3. But I need some help to get checked out your contact list with names and status. Contact list is created with XML data.

       

      XML file looks like this:

       

      <contacts>
      <contact>
      <name>User 1</name>
      <status>Online</status>
      </contact>
      <contact>
      <name>User 2</name>
      <status>Online</status>
      </contact>
      <contact>
      <name>User 3</name>
      <status>Busy</status>
      </contact>
      <contact>
      <name>User 4</name>
      <status>Online</status>
      </contact>
      <contact>
      <name>User 5</name>
      <status>Offline</status>
      </contact>
      <contact>
      <name>User 6</name>
      <status>Offline</status>
      </contact>
      </contacts>
      

       

      I want it to be printed out as follows:

       

      Image

       

      Hope someone can help me out:)

        • 1. Re: Contact list with xml
          rootsounds Level 4

          What aspect of this do you need help with?

          • 2. Re: Contact list with xml
            flex4

            Hi actstorm

             

             

                           What is the type do u want to print ... i image that u attached is not clear.. Please clear the question and elaborate it....

            • 3. Re: Contact list with xml
              rtalton Level 4

              You could use a List with a custom itemRenderer to accomplish this.

              • 4. Re: Contact list with xml
                actstorm Level 1

                Hi,

                 

                Here I come with a bit more thorough explanation. Contact list will be used for a chat client (IM).

                Contact lists are retrieved from an XML file and then print out include the name and status (icon).

                Each icon is located in a separate folder called icons. The function behind the contact list is the same as in msn messenger. The icon to see if the user is offline or online and also see the name of the user.

                What I need help with is to create a script that retrieves the XML data and displays it in a box (scroll) with a status icon and username.

                I hope this was a straightforward explanation

                • 5. Re: Contact list with xml
                  rootsounds Level 4

                  I'm not going to write it for you, but I will tell you what you will want to research:

                  • HTTPService for fetching the XML.
                  • List with a custom ListItemRenderer for the display.
                  • Probably embedding of an image as well.
                  1 person found this helpful
                  • 6. Re: Contact list with xml
                    actstorm Level 1

                    Hi,

                     

                    I've now got a script that retrieves and prints out the XML Data. How do I add line breaks and how can I get a click function that man can click on the information?

                     

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="service.send()" >
                         <mx:HTTPService id="service" url="contact.php" useProxy="false" result="serviceHandler(event)"/>
                    
                         <mx:Script>
                              <![CDATA[
                                   import mx.rpc.events.ResultEvent;
                                   import mx.controls.Alert;
                                   import mx.collections.ArrayCollection;
                                   [Bindable] private var condata : ArrayCollection;
                                   private function serviceHandler(e:ResultEvent):void{
                                        condata = e.result.contacts.contact;
                                   }
                              ]]>
                         </mx:Script>
                         <mx:Accordion width="400" height="400"
                              creationCompleteEffect="Iris" openDuration="500">
                              <mx:HBox >
                              <mx:Repeater id="rep" dataProvider="{condata}">
                              <mx:Image source="icons/status_{rep.currentItem.status}.png" />
                              <mx:Label text="{rep.currentItem.name}"/>     
                              <mx:Text text="{'\n'}"/>
                                   </mx:Repeater>
                                   </mx:HBox>
                         </mx:Accordion>
                    
                    </mx:WindowedApplication>
                    
                     
                     
                    

                     

                    Message was edited by: actstorm

                    • 7. Re: Contact list with xml
                      Matt Le Fevre Level 4

                      line breaks?

                       

                      i assume you mean arrange the items vertically.

                       

                      just wrap the repeater in a VBox instead of a HBox

                      1 person found this helpful
                      • 8. Re: Contact list with xml
                        actstorm Level 1

                        Thank you. But now I got a new problem now the icon over the text.

                         

                        Example

                         

                        [Icon]

                        User 1

                         

                        [Icon]

                        User 2

                        [Icon]

                        User 3

                        But I want the icon to be on the left side of the text
                        Like this

                         

                        [icon] User 1

                        [icon] User 2

                        [icon] User 3

                        • 9. Re: Contact list with xml
                          fleRavix Level 2

                          Take a repeater component, in that take an image control and a text control. Make the text control read-only

                          now, when u get the data from back-end in the form of xml, write the following the code,

                           

                          var dataObj:Object = new Object;

                          for each(item:xml in xmlData)

                          {

                              dataObj.uName = item.contacts.@name;

                              dataObj.status = item.contacts.@status;

                          }

                           

                          now loop the dataObj and find out where the status is online and busy.for each of that status, set the image src(from your imgaes asets).

                           

                           

                          mark this if helpful

                          • 10. Re: Contact list with xml
                            actstorm Level 1

                            I dont know where to post the code. Could you have put it where it should be?in the code I have added to the post.

                             

                            PS! I am new to flex

                             

                            <?xml version="1.0" encoding="utf-8"?>
                            <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="service.send()" >
                                 <mx:HTTPService id="service" url="contact.php" useProxy="false" result="serviceHandler(event)"/>
                            
                                 <mx:Script>
                                      <![CDATA[
                                           import mx.rpc.events.ResultEvent;
                                           import mx.controls.Alert;
                                           import mx.collections.ArrayCollection;
                                           [Bindable] private var condata : ArrayCollection;
                                           private function serviceHandler(e:ResultEvent):void{
                                                condata = e.result.contacts.contact;
                                           }
                                      ]]>
                                 </mx:Script>
                                 <mx:Accordion width="400" height="400"
                                      creationCompleteEffect="Iris" openDuration="500">
                                      <mx:HBox >
                                      <mx:Repeater id="rep" dataProvider="{condata}">
                                      <mx:Image source="icons/status_{rep.currentItem.status}.png" />
                                      <mx:Label text="{rep.currentItem.name}"/>     
                                      <mx:Text text="{'\n'}"/>
                                           </mx:Repeater>
                                           </mx:HBox>
                                 </mx:Accordion>
                            
                            </mx:WindowedApplication>