cancel
Showing results for 
Search instead for 
Did you mean: 

flash island WDA Simulate DataSources Input for Development

LeonBoeijen
Explorer
0 Kudos

Hello,

Does anybody know how I can simulate a DataSource that comes from the WDA to the Flash-Island.

I am trying to create a FlashIsland and I looked at the function set dataSource example from Thomas Jung's WDA-GoogleMap.

During development for the flex project I would like to use some example data the would be send by the WDA to my FlashIsland.

I would like to fill that data during the init() of my Flex project. The data will only be pushed to the FlashIsland so no 'two-way' binding is needed.

e.g.: I know that in my WDA I have defined a DataSource named dataSource, which contains three Properties (var1, var2, var3).

The DataSource is a table containing e.g. three entries.

Any help is appreciated.

Leon

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello Leon,

>>Does anybody know how I can simulate a DataSource that comes from the WDA to the Flash-Island.

To simulate the data, the better approach would be to create an xml file with the simulated data and read that xml into an arraycollection and call the set method of the datasource.

As you have one datasource with 3 properties, let me explain with an example:

1. Create an xml file data.xml and enter the following in that file:


<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<root>
  <item>
    <userID>12345</userID>
   <firstName>User</firstName>
   <lastName>xyz</lastName>
  </item>
  <item>
    <userID>12346</userID>
   <firstName>User2</firstName>
   <lastName>xyz</lastName>  </item>
</root>

2. You have to define a HTTPService to read the xml file. Put the following mxml code in your flex application file.


 <mx:HTTPService id="service"
            url="data.xml"
            contentType="application/xml"
            resultFormat="xml"
            result="serv_result(event);"
            fault="serv_fault(event);" />

3. add the following code in the script block of flex application file.


private var simulatedData:ArrayCollection = new ArrayCollection;
			
      private function serv_result(evt:ResultEvent):void {
                /* Convert XMLNode to XMLDocument. */
                var xmlStr:String = evt.result.toString();
                var xmlDoc:XMLDocument = new XMLDocument(xmlStr);
                var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(true);
                var resultObj:Object = decoder.decodeXML(xmlDoc);
                var arr:ArrayCollection = new ArrayCollection;
                arr.addItem(resultObj.root.item);
                simulatedData = ArrayCollection(arr.getItemAt(0));
                
	 }

private function serv_fault(evt:FaultEvent):void {
	           Alert.show("Not able to load data from xml" + evt.message);  
	        }

private function readXML():void{
service.send();
}
			

4. Call readXML() method inside the event handler of initialize event of the flex application. And define an event handler applicationCompleteHandler for applicationComplete event of flex application.

Inside applicationCompleteHandler, call the set method of datasource in the following way:


 private function applicationCompleteHandler():void
            {
                datasource=simulatedData; //datsource is the setter method here
		}

the setter method datasource can be the same as the one you use to read data from WDA.

Please let me know if you need more info!

Regards,

Srilatha