6 Replies Latest reply on Sep 9, 2009 2:10 PM by cyber0897

    need help with httpservice and trees...

    cyber0897 Level 1

      hey guys, i need some help with building a tree in flash builder,

      im using httpservice in action script to get the xml data from the link, http://www.apxalarm.com/pages/getnav

       

      the code im using for the http service is:

       

      public var navData:ArrayCollection;

       

      public function initNavTab():void{
          var navService:HTTPService = new HTTPService();
          navService.url = "http://www.apxalarm.com/pages/getnav";
          navService.method = "POST";
          navService.useProxy = false;
          navService.resultFormat = "array";
          navService.addEventListener(ResultEvent.RESULT, returnNavData);
          navService.addEventListener(FaultEvent.FAULT, navDataFault);
          navService.send();
      }

       

      public function returnNavData(event:ResultEvent):void{
          navData = event.result as ArrayCollection;
      }

       

      public function navDataFault(event:FaultEvent):void{
          Alert.show(event.fault.faultDetail);
      }

       

       

      i just need the navData to populate the tree component in the mxml... but unfortunately everytime i run the program, it just shows me [Object, Object]

       

      ive been stuck with this problem for a while.... please help

        • 1. Re: need help with httpservice and trees...
          cyber0897 Level 1

          hey guys, i just figured out a few things, but i still cannot see any children in the tree.... any help will be appretiated!!!

           

          the following is the modified code, the only problem is it just displays the name btu no children... the children are in the subNav tag of the xml

           

          public function initNavTab():void{
              var navService:HTTPService = new HTTPService();
              navService.url = "http://www.apxalarm.com/pages/getnav";
              navService.method = "POST";
              navService.useProxy = false;
              //navService.resultFormat = "e4x";
              navService.addEventListener(ResultEvent.RESULT, returnNavData);
              navService.addEventListener(FaultEvent.FAULT, navDataFault);
              navService.send();
          }

           

          public function returnNavData(event:ResultEvent):void{
              navData = event.result;
              Alert.show("load complete");
          }

           

          public function navDataFault(event:FaultEvent):void{
              Alert.show(event.fault.faultDetail);
          }

           

          public function tree_labelFunc(item:Object):String{
              var label:String = "";
              if(tree.dataDescriptor.hasChildren(item)){
                  label = item.section.length;
              }
              return item.name + label;
          }

           

           

          <mx:Tree id="tree" dataProvider="{navData.siteMap.sections.section}" labelFunction="tree_labelFunc" width="50%" height="100%" />

           

           

          again any help will be greatly appretiated!!!

          • 2. Re: need help with httpservice and trees...
            cyber0897 Level 1

            so..... anyone with any ideas?? im completely lost...

            • 3. Re: need help with httpservice and trees...
              Flex harUI Adobe Employee

              Depends on what the XML looks like.

               

              I see that you're setting the dataProvider to "...sections.section" which means that it is unlikely that in the labelFunction that there would be a item.section.

               

              Use toXMLString() to see what is in the nodes in the label function.

               

              Alex Harui

              Flex SDK Developer

              Adobe Systems Inc.

              Blog: http://blogs.adobe.com/aharui

              • 4. Re: need help with httpservice and trees...
                cyber0897 Level 1

                hey Alex, thank you soo much for replying to my post!!

                im not sure what im doin wrong here... but this i what i have for the tree_labelFunc, i modifided a little bit..

                 

                public function initNavTab():void{
                    var navService:HTTPService = new HTTPService();
                    navService.url = "http://www.apxalarm.com/pages/getnav";
                    navService.method = "POST";
                    navService.useProxy = false;
                    navService.resultFormat = "e4x";

                    navService.addEventListener(ResultEvent.RESULT, returnNavData);
                    navService.addEventListener(FaultEvent.FAULT, navDataFault);
                    navService.send();
                }

                 

                public function returnNavData(event:ResultEvent):void{
                    navData = event.result;
                    //resultArr = event.result;
                    Alert.show("load complete");
                    intepritXml(navData);
                }

                 

                public function navDataFault(event:FaultEvent):void{
                    Alert.show(event.fault.faultDetail);
                }

                 

                public function tree_labelFunc(item:Object):String{
                    var node:XML = XML(item);

                     trace(node.toXMLString().length);

                        return item.name;

                }

                the trace returns me a huge number 5668, which i think is wayy too big... so it cannot be accurate...

                i also changed my mxml some... i have the following in there right now

                 

                <mx:Tree id="tree" dataProvider="{navData}" labelField="name" labelFunction="tree_labelFunc" showRoot="false" width="50%" height="100%" />

                 

                 

                the tree first shows me a blank folder in the begining for the section (im assuming)

                then i see the names... and when i expand one of the section i get more no named folders... and when i expand the last folder i get the names i was looking for...

                 

                if that makes any sence at all!

                 

                i need it to display the following, when the program initiates

                 

                  + About APX

                  + APX Security Systems

                  + Customer Support

                  + .....

                   .....

                   + Newsroom

                 

                these are the "name" tags of each section in the xml...

                 

                 

                again thank you sooo much for replying you are a life saver!!

                 

                --T

                • 5. Re: need help with httpservice and trees...
                  Flex harUI Adobe Employee

                  You are not using toXMLString() correctly.  That just showed you the string length of the string representation of the XML.  Normally you just trace(node.toXMLString()) so you can see what the attributes and subnodes of node are.  Then you'll have a better idea of how to pull the data you want from it.

                   

                  We won't really be able to help you unless you show us what the XML looks like in those nodes.

                   

                  Alex Harui

                  Flex SDK Developer

                  Adobe Systems Inc.

                  Blog: http://blogs.adobe.com/aharui

                  • 6. Re: need help with httpservice and trees...
                    cyber0897 Level 1

                    hey thanks again for the quick responce!

                     

                    i made a few more modifications to the code... the following is the modified code... and the mxml in the project... i was thinkin that i shuold just populate the tree directly from the tree_labelFunc function... (i dont have the code that will provide the dataprovider for the tree in tehre... )

                     

                    and after that is the node.toXMLString() code...

                     

                     

                    public function initNavTab():void{
                        var navService:HTTPService = new HTTPService();
                        navService.url = "http://www.apxalarm.com/pages/getnav";
                        navService.method = "POST";
                        navService.useProxy = false;
                        navService.resultFormat = "e4x";
                        //navService.resultFormat = "array";
                        navService.addEventListener(ResultEvent.RESULT, returnNavData);
                        navService.addEventListener(FaultEvent.FAULT, navDataFault);
                        navService.send();
                    }

                     

                    public function returnNavData(event:ResultEvent):void{
                        navData = event.result;
                        //resultArr = event.result;
                        Alert.show("load complete");
                        tree_labelFunc(navData);
                    }

                     

                    public function navDataFault(event:FaultEvent):void{
                        Alert.show(event.fault.faultDetail);
                    }

                     

                    public function intepritXml(data:Object):void{
                        var i:Number = 0;
                       
                    }

                     

                    public function tree_labelFunc(item:Object):void{
                        var node:XML = XML(item);
                        var i:Number = 0;
                        trace(node.toXMLString());

                    }

                     

                     

                    <mx:Tree id="tree" showRoot="false" width="50%" height="100%" />

                     

                    ------------------------------------------------------------------------------------------ ------------------


                    toXMLString code: the only thing i want from the following is the data in the tags "name" but i also need the other tags to be available, but not displayed in the tree...

                     

                    <siteMap>
                      <sections>
                        <section>
                          <name>About APX</name>
                          <urlName>about</urlName>
                          <position>1</position>
                          <defaultaction>/about/mission</defaultaction>
                          <navs>
                            <nav>
                              <name>Our Mission</name>
                              <urlName>mission</urlName>
                              <position>1</position>
                              <defaultaction>13</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Links</name>
                              <urlName>links</urlName>
                              <position>4</position>
                              <subNavs>
                                <nav>
                                  <name>iamapx.com</name>
                                  <urlName>iamapx</urlName>
                                  <position>1</position>
                                  <defaultaction>http://www.iamapx.com</defaultaction>
                                  <subNavs/>
                                </nav>
                                <nav>
                                  <name>apxgivesback.com</name>
                                  <urlName>agb</urlName>
                                  <position>2</position>
                                  <defaultaction>http://www.apxgivesback.com</defaultaction>
                                  <subNavs/>
                                </nav>
                              </subNavs>
                            </nav>
                            <nav>
                              <name>Newsletter</name>
                              <urlName>newsletter</urlName>
                              <position>3</position>
                              <defaultaction>37</defaultaction>
                              <subNavs/>
                            </nav>
                          </navs>
                        </section>
                        <section>
                          <name>APX Security Systems</name>
                          <urlName>apxsystems</urlName>
                          <position>2</position>
                          <defaultaction>/apxsystems/systems/products</defaultaction>
                          <navs>
                            <nav>
                              <name>Service Areas</name>
                              <urlName>serviceareas</urlName>
                              <position>1</position>
                              <defaultaction>25</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Systems</name>
                              <urlName>systems</urlName>
                              <position>2</position>
                              <defaultaction>27</defaultaction>
                              <subNavs>
                                <nav>
                                  <name>Get A System</name>
                                  <urlName>get</urlName>
                                  <position>2</position>
                                  <defaultaction>27</defaultaction>
                                  <subNavs/>
                                </nav>
                                <nav>
                                  <name>Browse Products</name>
                                  <urlName>products</urlName>
                                  <position>1</position>
                                  <defaultaction>28</defaultaction>
                                  <subNavs/>
                                </nav>
                                <nav>
                                  <name>Refer A Friend</name>
                                  <urlName>refer</urlName>
                                  <position>3</position>
                                  <defaultaction>38</defaultaction>
                                  <subNavs/>
                                </nav>
                              </subNavs>
                            </nav>
                          </navs>
                        </section>
                        <section>
                          <name>Customer Support</name>
                          <urlName>support</urlName>
                          <position>3</position>
                          <defaultaction>/support/specialist</defaultaction>
                          <navs>
                            <nav>
                              <name>Technical Support</name>
                              <urlName>tech</urlName>
                              <position>2</position>
                              <defaultaction>32</defaultaction>
                              <subNavs>
                                <nav>
                                  <name>Troubleshooting</name>
                                  <urlName>troubleshooting</urlName>
                                  <position>2</position>
                                  <defaultaction>32</defaultaction>
                                  <subNavs/>
                                </nav>
                              </subNavs>
                            </nav>
                            <nav>
                              <name>Speak To A Specialist</name>
                              <urlName>specialist</urlName>
                              <position>1</position>
                              <defaultaction>30</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Move Options</name>
                              <urlName>moves</urlName>
                              <position>3</position>
                              <defaultaction>35</defaultaction>
                              <subNavs/>
                            </nav>
                          </navs>
                        </section>
                        <section>
                          <name>Home Safety</name>
                          <urlName>safety</urlName>
                          <position>4</position>
                          <defaultaction>/safety/outside</defaultaction>
                          <navs>
                            <nav>
                              <name>Indoor Tips</name>
                              <urlName>inside</urlName>
                              <position>1</position>
                              <defaultaction>17</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Outdoor Tips</name>
                              <urlName>outside</urlName>
                              <position>2</position>
                              <defaultaction>18</defaultaction>
                              <subNavs/>
                            </nav>
                          </navs>
                        </section>
                        <section>
                          <name>Customer Stories</name>
                          <urlName>stories</urlName>
                          <position>5</position>
                          <defaultaction>/stories/videos</defaultaction>
                          <navs>
                            <nav>
                              <name>Videos</name>
                              <urlName>videos</urlName>
                              <position>3</position>
                              <defaultaction>15</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Read Stories</name>
                              <urlName>read</urlName>
                              <position>1</position>
                              <defaultaction>19</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Tell Your Story</name>
                              <urlName>tell</urlName>
                              <position>2</position>
                              <defaultaction>20</defaultaction>
                              <subNavs/>
                            </nav>
                          </navs>
                        </section>
                        <section>
                          <name>Newsroom</name>
                          <urlName>press</urlName>
                          <position>6</position>
                          <defaultaction>/press/compprofile</defaultaction>
                          <navs>
                            <nav>
                              <name>Press Releases</name>
                              <urlName>pr</urlName>
                              <position>2</position>
                              <defaultaction>21</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Media Kit</name>
                              <urlName>media</urlName>
                              <position>3</position>
                              <defaultaction>22</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Company Profile</name>
                              <urlName>compprofile</urlName>
                              <position>1</position>
                              <defaultaction>34</defaultaction>
                              <subNavs/>
                            </nav>
                            <nav>
                              <name>Contact Us</name>
                              <urlName>contact</urlName>
                              <position>4</position>
                              <defaultaction>39</defaultaction>
                              <subNavs/>
                            </nav>
                          </navs>
                        </section>
                      </sections>
                    </siteMap>

                     

                     

                    thank you soo much!!

                     

                    --T