topical media & game development
mashup-rmx-07-Chapter7-Exercise1-Chapter7-Exercise1.mx
mashup-rmx-07-Chapter7-Exercise1-Chapter7-Exercise1.mx
(swf
)
[ flash
]
flex
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
initialize="init()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
import mx.utils.*;
import mx.managers.*;
import com.almerblank.utils.ServiceUtility;
private var amfphp:ServiceUtility = ServiceUtility.getInstance();
private const GATEWAY:String = 'http://amfphp:8888/gateway.php';
private const POLICY:String = 'http://amfphp:8888/crossdomain.xml';
[Bindable] private var productsDP:ArrayCollection;
[Bindable] private var offset:uint = 0;
[Bindable] private var pageSize:uint;
[Bindable] private var totalProducts:uint;
[Bindable] private var previousVisible:Boolean = false;
[Bindable] private var nextVisible:Boolean = true;
private function init():void{
amfphp.init(GATEWAY, false, null);
getProducts(0);
}
private function getProducts(startID:uint):void{
amfphp.call('com.almerblank.ISBN8962.Ch7.Products.browse', resultHandler, faultHandler, startID);
CursorManager.setBusyCursor();
}
private function resultHandler(result:Array):void{
try {
productsDP = new ArrayCollection(result);
pageSize = productsDP.getItemAt(5).pageSize;
offset = productsDP.getItemAt(5).offset;
totalProducts = productsDP.getItemAt(5).totalProducts;
setButtonVisibility();
trace('offset = '+offset+'\npageSize = '+pageSize+'\ntotalProducts = '+totalProducts);
} catch(error:*) {
trace('get products error: '+error.message);
} finally {
CursorManager.removeBusyCursor();
}
}
private function faultHandler(fault:Object):void{
Alert.show(fault.description, 'Service Error:');
}
private function setButtonVisibility():void{
previousVisible = (offset > 0) ? true : false;
nextVisible = (totalProducts > offset + pageSize) ? true : false;
}
]]>
</mx:Script>
<mx:DataGrid
x="141"
y="70"
id="dgProducts"
dataProvider="{productsDP}"
width="900">
<mx:columns>
<mx:DataGridColumn
headerText="Prod. ID"
dataField="product_id"
width="60"/>
<mx:DataGridColumn
headerText="Product"
dataField="product_name"/>
<mx:DataGridColumn
headerText="Description"
dataField="product_desc"/>
<mx:DataGridColumn
headerText="Price"
dataField="product_price" width="80"/>
</mx:columns>
</mx:DataGrid>
<mx:Button
x="141"
y="244"
id="previousPage"
label="Previous"
visible="{previousVisible}"
click="getProducts(offset-pageSize)"/>
<mx:Button
x="{dgProducts.width-2}"
y="244"
id="nextPage"
label="Next"
visible="{nextVisible}"
click="getProducts(offset+pageSize)"/>
</mx:Application>
(C) Æliens
18/6/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.