2 Replies Latest reply on Oct 9, 2011 2:16 AM by ccsnet

    XML In To Flex Mobile

    ccsnet

      I wonder if you can help me.... I'm new to Flex so I've been playing with a demo app from Lynda which with out mods loads simple xml as a demo and shows it as a list.

       

      I've tried to take that and use a more complex xml file with some info I source from else where and I seem to not be able to process it. TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@xxxx to XML comes upo which I believe is about placing XML in to an array where as it should be an object ? I've looked at a number of code snippets but there seems to be a number of ways to do this and I'm going round and round.

       

      I'd appriciate any help you may be able to give me been a complete noob.

       

      Terran

       

       

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

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

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

                                                                            splashScreenImage="@Embed('images/tmsplashscreen.jpg') "

                                                                            persistNavigatorState="true"

                                                                            creationComplete="getUnplanned.send()">

                <fx:Script>

                          <![CDATA[

                                    import mx.collections.ArrayCollection;

                                    import mx.core.FlexGlobals;

                                    import mx.rpc.events.ResultEvent;

                                    import views.MainHomeView;

       

                                    [Bindable]

                                    //make this work with xml

                                    protected var myUnplanned:ArrayCollection;

       

                                    // May not need this line

                                    ;

                                    protected function getUnplanned_resultHandler(event:ResultEvent):void

                                    {

       

                                              // TODO Auto-generated method stub

                                              myUnplanned = event.result.payloadPublication.situation

                                              navigator.pushView(views.MainHomeView, event.result.payloadPublication.situation);

                                    }

                          ]]>

                </fx:Script>

                <fx:Declarations>

                          <!-- Place non-visual elements (e.g., services, value objects) here -->

                          <s:HTTPService url="http://www.letscommunicate.co.uk/xxxxxxxxxxxxx/xmldisunplannedevente.php"

                                                           id="getUnplanned"

                                                           resultFormat="e4x"

                                                           result="getUnplanned_resultHandler(event)"/>

                </fx:Declarations>

                <s:navigationContent>

                          <s:Button label="Back" click="navigator.popView()"/>

                          <s:Button label="Menu" click="mx.core.FlexGlobals.topLevelApplication.viewMenuOpen=true"/>

                </s:navigationContent>

      </s:ViewNavigatorApplication>

        • 1. Re: XML In To Flex Mobile
          Shongrunden Adobe Employee

          Here's a simple example that appears to work:

           

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

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

                         creationComplete="getUnplanned.send()">

              <fx:Script>

                  <![CDATA[

                      import mx.collections.XMLListCollection;

                      import mx.rpc.events.ResultEvent;

                     

                      [Bindable]

                      protected var myUnplanned:XMLListCollection;

                     

                      protected function getUnplanned_resultHandler(event:ResultEvent):void

                      {

                          var xml:XML = new XML(event.result);

                         

                          myUnplanned = new XMLListCollection(new XMLList(xml.children()));

                          myList.dataProvider = myUnplanned;

                      }

                      private function myLabelFunction(item:Object):String {

                          return item.TITLE;

                      }

                  ]]>

              </fx:Script>

              <fx:Declarations>

                  <s:HTTPService id="getUnplanned" url="http://www.w3schools.com/xml/cd_catalog.xml" resultFormat="e4x" result="getUnplanned_resultHandler(event)"/>

              </fx:Declarations>

              <s:List id="myList" labelFunction="myLabelFunction"/>

          </s:Application>

          • 2. Re: XML In To Flex Mobile
            ccsnet Level 1

            Thanks very much - Ill give this a go.

             

            Terran