macromedia flash handhelds:
I have this app. There is a drop down box dynamicaly populated. It works ok on
my pocketPC but only if it syncs up. How can I load the selection in to a
SharedObject (im thinking) and then I could use the app unconnected? My next
problem is that I dont know hoe to have other selections get added to the grid
im using as the 'Cart' I then want to send the items that get added using and
add button (add_pb) to the grid (cart_dg) I have a send button (buy_pb) The
adding of the items works ok and the saving to the device works good but the
send from the device does not seem to work even in the craddle connected. But
it does work in the runtime environment (Ctrl/Shift). Can anyone help me with
any of this? Thanks, George
/***********************************************
included ActionScript files
***********************************************/
#include "NetServices.as"
#include "NetDebug.as"
var gateway="
http://www.youngsmarket.com/flashservices/gateway"; var remoteProd="PocketPC.Products";
var remoteDist=" PocketPC.Distributor";
var remoteCart=" PocketPC.Carts";
/***********************************************
object constructors and object creation
***********************************************/
var prodResponder=new Object();
var cartResponder=new Object();
/***********************************************
functions and object methods
***********************************************/
cartResponder.onResult=function(result)
{
confirm_txt.text="Your confirmation number is "+result;
}
function objectFormatter(theObj,labelname)
{
var dataObj=new Object();
dataObj.label=theObj[labelname];
dataObj.data=theObj;
return dataObj;
}
prodResponder.onResult=function(result)
{
var prod_array=new Array();
for (var i=0;i<result.length;i++)
{
prod_array[i]=objectFormatter(result[i],"MBRANS");
}
prod_cb.setDataProvider(prod_array);
}
this.onStatus=function(result)
{
trace(result.description);
prod_cb.addItem("Error loading");
}
cart_dg.addToCart=function()
{
var newItem=true;
var num=this.getLength();
for (var i=0;i<=num;i++)
{
if(this.getItemAt(i).MBABRD==prod_cb.getSelectedItem().data.MBABRD)
{
newItem=false;
this.setCellData(i,"Quantity",Number(this.getItemAt(i).quantity)+1);
break;
}
}
if (newItem)
{
cart_dg.addItem(prod_cb.getSelectedItem().data);
this.setCellData(num,"Quantity",1);
}
trash_mc._alpha=100;
}
cart_dg.deleteItem=function(){
this.removeItemAt(this.getSelectedIndex());
}
cart_dg.saveCart=function()
{
cart_so.data.cart_array=new Array();
for (var i=0;i<cart_dg.getLength();i++)
{
cart_so.data.cart_array[i]=cart_dg.getItemAt(i);
}
cart_so.flush();
confirm_txt.text="Info saved!"
}
cart_dg.buy=function()
{
// create an array to hold the item objects
var cart_array=new Array();
// hardcode distributor ID
var distID=3;
// get the length of the cart (number of items)
var numItems=cart_dg.getLength();
// populate the array with the cart item objects
for (var i=0;i<numItems;i++)
{
cart_array[i]=cart_dg.getItemAt(i);
}
// call the buyCart method of the cart service
cartResponder.cartService.buyCart(cart_array,distID);
}
trash_mc.onRelease=function()
{
cart_dg.deleteItem();
}*/
/***********************************************
run at once commands
***********************************************/
NetServices.setDefaultGatewayURL(gateway);
var net_conn=NetServices.createGatewayConnection();
prodResponder.prodService=net_conn.getService(remoteProd,prodResponder);
prodResponder.prodService.getAll();
// populate product ListBox
prod_lb.addItem("Loading...");
// create proxy object for remote Cart service
cartResponder.cartService=net_conn.getService(remoteCart,cartResponder);
// skin all components
globalStyleFormat.selection=0x95FFAA;
globalStyleFormat.applyChanges();
// set click handler for add_pb
add_pb.setClickHandler("addToCart",cart_dg);
// Set columns to display in DataGrid
cart_dg.setColumns("MBRANS","POS");
// Set column headers
cart_dg.getColumnAt(0).setHeader("Product");
//cart_dg.getColumnAt(1).setHeader("Price");
// Add new columns to the DataGrid
var newCol=new FGridColumn("Quantity");
cart_dg.addColumn(newCol);
// set column widths
cart_dg.getColumnAt(0).setWidth(130);
//cart_dg.getColumnAt(1).setWidth(60);
cart_dg.getColumnAt(2).setWidth(60);
cart_dg.getColumnAt(3).setWidth(60);
// make quantity column editable
cart_dg.setEditable(true);
cart_dg.getColumnAt(0).setEditable(false);
//cart_dg.getColumnAt(1).setEditable(false);
cart_dg.getColumnAt(3).setEditable(false);
// format DataGRid appearance
cart_dg.alternateRowColors(0xffffff,0xECFFEC);
// set FStyleFormat object properties
cart_dg.setStyleProperty("header",0xBFD5FF);
//cart_dg.getColumnAt(3).setStyleProperty("textAlign","right");
// create or find a shared object in the local drive
cart_so=SharedObject.getLocal("cartInfo");
// set click handler for save_pb, also added to stage in this wt
save_pb.setClickHandler("saveCart",cart_dg);
// autosize a dynamic message field for confirmations
confirm_txt.autosize=true;
// length of array of products in sharedobject array
var soNum=cart_so.data.cart_array.length;
// check to see if any items in shared object, if there are, add them to the
cart
if (soNum>0)
{
for (var i=0;i<soNum;i++)
{
cart_dg.addItem(cart_so.data.cart_array[i]);
}
cart_dg.totalCart();
}
// set clickHandler for buy_pb
buy_pb.setClickHandler("buy",cart_dg);
trash_mc._alpha=20;