Hi,
Here i post the nice example for choose the book from the list and enter the quantity of the book that they want. Then pass the information to the paypal application and we can see the amount of product that we order from the flex application. In below i given the code for that.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInit()">
<mx:Script>
<![CDATA[
import flash.net.navigateToURL;
private var _cmbArr:Array;
private function onInit():void
{
var _urlRequest:URLRequest = new URLRequest("xmls/bookList.xml");
var _urlLoader:URLLoader = new URLLoader();
_urlLoader.addEventListener(Event.COMPLETE,onXMLLoadComplete);
_urlLoader.load(_urlRequest);
}
private function onXMLLoadComplete(evt:Event):void
{
_cmbArr = new Array();
var _xml:XML = XML(evt.target.data);
var _xmlList:XMLList = XMLList(_xml.book);
_cmbArr.push("Select Product");
for(var i:int=0;i<_xmlList.length();i++)
{
_cmbArr.push({label:_xmlList[i].@name,id:_xmlList[i].@id,price:_xmlList[i].@price,tax:_xmlList[i].@tax,mail:_xmlList[i].@ordermail,thumb:_xmlList[i].@thumburl});
}
cmb_product.dataProvider = _cmbArr;
}
private function onProductChange(evt:Event):void
{
txt_prodid.text = cmb_product.selectedItem.id;
txt_amt.text = cmb_product.selectedItem.price;
txt_tax.text = cmb_product.selectedItem.tax;
img_src.source = cmb_product.selectedItem.thumb;
txt_desc.text = cmb_product.selectedItem.label;
}
private function makePayment():void
{
var url:String = "http://www.paypal.com/cgi-bin/webscr";
var _urlRequest:URLRequest = new URLRequest(url);
var _urlVar:URLVariables = new URLVariables();
_urlVar.cmd = "_xclick";
_urlVar.currency_code = "USD";
_urlVar.business = cmb_product.selectedItem.mail;
_urlVar.item_number = cmb_product.selectedItem.id;
_urlVar.item_name = cmb_product.selectedItem.label;
_urlVar.amount = cmb_product.selectedItem.price;
_urlVar.quantity = txt_qty.text;
_urlVar.tax = cmb_product.selectedItem.tax;
_urlRequest.data = _urlVar;
_urlRequest.method = URLRequestMethod.POST;
navigateToURL(_urlRequest,"_parent");
}
]]>
</mx:Script>
<mx:HBox paddingLeft="20" paddingTop="20">
<mx:Form backgroundColor="#FFFFFF" height="240">
<mx:Label width="100%" text="Product Catalogue" fontFamily="Arial" fontSize="15" fontWeight="bold" textAlign="center"/>
<mx:FormItem label="Choose Item :" fontFamily="Arial" fontSize="12">
<mx:ComboBox id="cmb_product" width="150" height="23" fontFamily="Arial" fontSize="12" change="onProductChange(event)"/>
</mx:FormItem>
<mx:FormItem label="Product ID :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_prodid" editable="false" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem label="Amount :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_amt" editable="false" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem label="Quantity :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_qty" text="1" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem label="Tax :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_tax" editable="false" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem>
<mx:Image source="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" width="60" maintainAspectRatio="true" horizontalCenter="0" verticalCenter="0" click="makePayment()"/>
</mx:FormItem>
</mx:Form>
<mx:VRule height="100%" strokeColor="#CCCCCC"/>
<mx:VBox height="240" backgroundColor="#666666">
<mx:Image id="img_src" width="250" height="200" verticalAlign="bottom" horizontalAlign="center"/>
<mx:Text id="txt_desc" fontFamily="Arial" fontSize="12" textAlign="center" fontWeight="bold" color="#FFFFFF" width="100%" height="20"/>
</mx:VBox>
</mx:HBox>
</mx:Application>
The sample xml file for accessing those above example as follows
<?xml version="1.0" encoding="UTF-8"?>
<BookList>
<book id="201" name="Cool 3D" price="250" tax="2" ordermail="order@macromedia.com" thumburl="assets/images/cool3d.jpg"/>
<book id="010" name="Dream Weaver" price="180" tax="4" ordermail="order@adobe.com" thumburl="assets/images/dreamweaver.gif"/>
<book id="001" name="Dream WeaverMX" price="300" tax="2" ordermail="order@adobe.com" thumburl="assets/images/dreamweavermx.gif"/>
<book id="413" name="Open Suse" price="280" tax="6" ordermail="order@sunsystems.com" thumburl="assets/images/opensuse.png"/>
<book id="271" name="Software Application" price="320" tax="4" ordermail="order@microsoft.com" thumburl="assets/images/swapp.jpg"/>
</BookList>
Here i post the nice example for choose the book from the list and enter the quantity of the book that they want. Then pass the information to the paypal application and we can see the amount of product that we order from the flex application. In below i given the code for that.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="onInit()">
<mx:Script>
<![CDATA[
import flash.net.navigateToURL;
private var _cmbArr:Array;
private function onInit():void
{
var _urlRequest:URLRequest = new URLRequest("xmls/bookList.xml");
var _urlLoader:URLLoader = new URLLoader();
_urlLoader.addEventListener(Event.COMPLETE,onXMLLoadComplete);
_urlLoader.load(_urlRequest);
}
private function onXMLLoadComplete(evt:Event):void
{
_cmbArr = new Array();
var _xml:XML = XML(evt.target.data);
var _xmlList:XMLList = XMLList(_xml.book);
_cmbArr.push("Select Product");
for(var i:int=0;i<_xmlList.length();i++)
{
_cmbArr.push({label:_xmlList[i].@name,id:_xmlList[i].@id,price:_xmlList[i].@price,tax:_xmlList[i].@tax,mail:_xmlList[i].@ordermail,thumb:_xmlList[i].@thumburl});
}
cmb_product.dataProvider = _cmbArr;
}
private function onProductChange(evt:Event):void
{
txt_prodid.text = cmb_product.selectedItem.id;
txt_amt.text = cmb_product.selectedItem.price;
txt_tax.text = cmb_product.selectedItem.tax;
img_src.source = cmb_product.selectedItem.thumb;
txt_desc.text = cmb_product.selectedItem.label;
}
private function makePayment():void
{
var url:String = "http://www.paypal.com/cgi-bin/webscr";
var _urlRequest:URLRequest = new URLRequest(url);
var _urlVar:URLVariables = new URLVariables();
_urlVar.cmd = "_xclick";
_urlVar.currency_code = "USD";
_urlVar.business = cmb_product.selectedItem.mail;
_urlVar.item_number = cmb_product.selectedItem.id;
_urlVar.item_name = cmb_product.selectedItem.label;
_urlVar.amount = cmb_product.selectedItem.price;
_urlVar.quantity = txt_qty.text;
_urlVar.tax = cmb_product.selectedItem.tax;
_urlRequest.data = _urlVar;
_urlRequest.method = URLRequestMethod.POST;
navigateToURL(_urlRequest,"_parent");
}
]]>
</mx:Script>
<mx:HBox paddingLeft="20" paddingTop="20">
<mx:Form backgroundColor="#FFFFFF" height="240">
<mx:Label width="100%" text="Product Catalogue" fontFamily="Arial" fontSize="15" fontWeight="bold" textAlign="center"/>
<mx:FormItem label="Choose Item :" fontFamily="Arial" fontSize="12">
<mx:ComboBox id="cmb_product" width="150" height="23" fontFamily="Arial" fontSize="12" change="onProductChange(event)"/>
</mx:FormItem>
<mx:FormItem label="Product ID :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_prodid" editable="false" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem label="Amount :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_amt" editable="false" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem label="Quantity :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_qty" text="1" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem label="Tax :" fontFamily="Arial" fontSize="12">
<mx:TextInput id="txt_tax" editable="false" width="150" height="23"/>
</mx:FormItem>
<mx:FormItem>
<mx:Image source="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" width="60" maintainAspectRatio="true" horizontalCenter="0" verticalCenter="0" click="makePayment()"/>
</mx:FormItem>
</mx:Form>
<mx:VRule height="100%" strokeColor="#CCCCCC"/>
<mx:VBox height="240" backgroundColor="#666666">
<mx:Image id="img_src" width="250" height="200" verticalAlign="bottom" horizontalAlign="center"/>
<mx:Text id="txt_desc" fontFamily="Arial" fontSize="12" textAlign="center" fontWeight="bold" color="#FFFFFF" width="100%" height="20"/>
</mx:VBox>
</mx:HBox>
</mx:Application>
The sample xml file for accessing those above example as follows
<?xml version="1.0" encoding="UTF-8"?>
<BookList>
<book id="201" name="Cool 3D" price="250" tax="2" ordermail="order@macromedia.com" thumburl="assets/images/cool3d.jpg"/>
<book id="010" name="Dream Weaver" price="180" tax="4" ordermail="order@adobe.com" thumburl="assets/images/dreamweaver.gif"/>
<book id="001" name="Dream WeaverMX" price="300" tax="2" ordermail="order@adobe.com" thumburl="assets/images/dreamweavermx.gif"/>
<book id="413" name="Open Suse" price="280" tax="6" ordermail="order@sunsystems.com" thumburl="assets/images/opensuse.png"/>
<book id="271" name="Software Application" price="320" tax="4" ordermail="order@microsoft.com" thumburl="assets/images/swapp.jpg"/>
</BookList>
eth
ReplyDelete