2 Replies Latest reply on Aug 19, 2007 2:15 PM by lukemack

    Build advice

    lukemack Level 1
      hi,

      i am building a flex app which is a world map with destination labels e.g. north america. when the user hovers over the label for north america, a listbox should appear containing the names of holiday companies which go there. the holiday companies are in an xml file which i have successfully accessed using a datagrid for testing. the xml file will be updated from a database using php (that part is covered).

      what i need to know is what method to use for getting the data into actionscript so that i can manipulate it and populate listboxes, according to where the user's mouse is.

      the remote xml example in the help files doesn't work and I'm not used to AS3 (I have used as2 in flash 8). Normally I would populate some arrays with the XML data and use those arrays to populate the listboxes. Please can someone let me know how to do that in Flex Builder 2 with AS3, including whether I need to add import statement in my mx:script tags?

      thanks!

      lukemack.
        • 1. Re: Build advice
          ntsiii Level 3
          Below is some sample code. Post if you do not understand something.
          Tracy

          Sample code using HTTPService, e4x, handler function to populate a list item.
          Also shows usage of AsyncToken.

          The DataGrid tag:
          <mx:DataGrid id="dg" dataProvider="{_xlcMyListData}" .../>


          The HTTPService tag:
          <mx:HTTPService id="service" resultFormat="e4x" result="onResult(event)" fault="..../>

          Script block declaration:
          import mx.rpc.Events.ResultEvent;
          [Bindable]private var _xlcMyListData:XMLListCollection;

          Invoke send:
          var oRequest:Object = new Object();
          oRequest.Arg1 = "value1";
          var callToken:AsyncToken = service.send(oRequest);
          token.callId = "myQuery1";

          Result Handler function:
          private function onResult(oEvent:ResultEvent):void {
          var xmlResult:XML = XML(event.result); //converts result Object to XML. can also use "as" operator
          var xlMyListData:XMLList = xmlResult.myListData; //depends on xml format, is row data
          _xlcMyListData = new XMLListCollection(xlMyListData); //wrap the XMLList in a collection
          trace(_xlcMyListData.toXMLString()); //so you can see exactly how to specify dataField or build labelFunction
          var callToken:AsyncToken = oEvent.token;
          var sCallId = callToken.callId; //"myQuery1"
          switch(sCallId) {
          case "myQuery1":
          doQuery2();
          break;
          ...
          }
          }//onResult
          • 2. Re: Build advice
            lukemack Level 1
            Thanks very much for taking the time to provide a sample. I did it using an XMLList in the end.