Ice for ActionScript
Ice for ActionScript is a native implementation of the Ice run time that greatly simplifies the task of building robust, network-aware applications for Adobe Flash and Adobe AIR. As ActionScript's reach extends beyond the browser to desktops, mobile devices, and smart appliances, developers now have a powerful distributed computing solution for seamlessly integrating these disparate platforms.
Sample Code
To illustrate how Ice is used with ActionScript, consider the following Slice interface definitions:
module Biz {
struct Item {
string sku;
int qty;
};
sequence<Item> ItemSeq;
interface Invoice {
void addItems(ItemSeq items);
void submit();
};
interface InvoiceFactory {
Invoice* create();
};
};
ActionScript code that creates an invoice using the factory is shown below:
// Create a proxy for the invoice factory object.
var proxy:Ice.ObjectPrx = communicator.stringToProxy("InvoiceFactory:tcp -p 9000");
// Narrow the proxy to the proper type.
var factory:Biz.InvoiceFactoryPrx = Biz.InvoiceFactoryPrxHelper.uncheckedCast(proxy);
// Use the factory to obtain a proxy for a new invoice object.
factory.create().whenCompleted(createCompleted, handleException);
...
function createCompleted(r:Ice.AsyncResult, invoice:Biz.InvoicePrx):void
{
// Add items to the invoice.
var items:Vector. items = new Vector.();
items[0] = new Biz.Item();
items[0].sku = "10-6139";
items[0].qty = 3;
invoice.addItems(items).whenCompleted(
function(ar:Ice.AsyncResult):void
{
// Submit the invoice.
invoice.submit().whenCompleted(invoiceSubmitted, handleException);
},
handleException);
}
To avoid blocking ActionScript's only thread of execution, all remote Ice invocations
have asynchronous semantics. The return value of all proxy invocations is an
asynchronous result object, on which the application invokes whenCompleted
to configure handlers for success and failure. These handlers can be formally-declared
functions such as createCompleted, or anonymous functions declared inline.