I am new to Flex and ActionScript. Need help:
Modified the code found at:
http://learn.adobe.com/wiki/display/Flex/2b.+Code+Files///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
[Bindable]
private var shippingInfo:XMLList;
public function handleXML(event:ResultEvent):void
{
shippingInfo = event.result.report.table.tr as XMLList;
//Alert.show(shippingInfo.td);
//Alert.show(shippingInfo.td.(@colnum=='c0'));
//Alert.show(shippingInfo.td.(@colnum=='c1'));
}
public function handleFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, "Error");
}
]]>
</mx:Script>
<mx:HTTPService result="handleXML(event);"
fault="handleFault(event);" id="xmlRPC" resultFormat="e4x"
method="POST" url="
http://localhost/xml_test/test_flex.xml"useProxy="false">
<mx:request xmlns="">
<zipcode>{zipcode.text}</zipcode>
<pounds>{weight_lb.text}</pounds>
</mx:request>
</mx:HTTPService>
<mx:Label x="56" y="32" text="Zip Code" width="55"
height="18" textAlign="right" fontWeight="bold"/>
<mx:Label x="56" y="58" text="Weight" width="55"
height="18" textAlign="right" fontWeight="bold"/>
<mx:TextInput x="130" y="32" id="zipcode" width="160"
height="22"/>
<mx:TextInput x="130" y="58" id="weight_lb" width="160"
height="22"/>
<mx:Button x="130" y="95" label="Get Shipping Options"
click="xmlRPC.send();" width="160" height="22"/>
<mx:DataGrid
dataProvider="{shippingInfo}"
x="80" y="141" width="562" height="292"
id="shippingOptionsList" editable="false" enabled="true">
<mx:columns>
<mx:DataGridColumn headerText="Country" dataField="td"
/>
<mx:DataGridColumn headerText="Car" dataField="td2" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The above code works fine for the following XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<fxf version="1.0" data="hold">
<report records="5" lines="5" columns="2" rows="10">
<target format="" version="" type=""
destination="OUT"/>
<table>
<tr linetype="data" linenum="1">
<td colnum="c0">ENGLAND</td>
<td2 colnum="c1">JAGUAR</td2>
</tr>
<tr linetype="data" linenum="2">
<td colnum="c0">ENGLAND</td>
<td2 colnum="c1">JENSEN</td2>
</tr>
<tr linetype="data" linenum="3">
<td colnum="c0">ENGLAND</td>
<td2 colnum="c1">TRIUMPH</td2>
</tr>
<tr linetype="data" linenum="4">
<td colnum="c0">JAPAN</td>
<td2 colnum="c1">DATSUN</td2>
</tr>
<tr linetype="data" linenum="5">
<td colnum="c0">JAPAN</td>
<td2 colnum="c1">TOYOTA</td2>
</tr>
</table>
</report>
</fxf>
Now, my actual XML in Production world would look like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<fxf version="1.0" data="hold">
<report records="5" lines="5" columns="2" rows="10">
<target format="" version="" type=""
destination="OUT"/>
<table>
<tr linetype="data" linenum="1">
<td colnum="c0">ENGLAND</td>
<td colnum="c1">JAGUAR</td>
</tr>
<tr linetype="data" linenum="2">
<td colnum="c0">ENGLAND</td>
<td colnum="c1">JENSEN</td>
</tr>
<tr linetype="data" linenum="3">
<td colnum="c0">ENGLAND</td>
<td colnum="c1">TRIUMPH</td>
</tr>
<tr linetype="data" linenum="4">
<td colnum="c0">JAPAN</td>
<td colnum="c1">DATSUN</td>
</tr>
<tr linetype="data" linenum="5">
<td colnum="c0">JAPAN</td>
<td colnum="c1">TOYOTA</td>
</tr>
</table>
</report>
</fxf>
(Notice in this XML, under each <TR> you would find two
<TD>s)
Use this XML file, I am having problems. I need to specify
which TD goes into each column. Even if I use:
dataField=".(attribute('colnum')=='c0')"
it is not helping me.
Please help me. Thanks in advance.
- RT