|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectit.gotoandplay.smartfoxserver.lib.ActionscriptObject
public class ActionscriptObject
This the ActionscriptObject class emulates a generic AS object/array in Java. The object is used to send and receive data to and from the Flash client.
The object can contain:
Example #1:
The client sends an object containing a string and a number, like this:
var obj:Object = {}
obj.str = "Hey I am string"
obj.num = 100
You will receive an ActionscriptObject instance, called ao:
String str = ao.getString("str");
int num = (int) ao.getNumber("num");
Example #2:
A slightly more complex example showing how to deal with nested objects.
This time we also have an array of numbers.
var obj:Object = {}
obj.str = "Hey I am string"
obj.num = 100
obj.arr = [1,2,3,4,5]
You will receive an ActionscriptObject instance, called ao:
String str = ao.getString("str");
int num = (int) ao.getNumber("num");
ActionscriptObject arr = ao.getObj("arr");
// Cycle through all items
for (int i = 0; i < arr.size(); i++)
{
System.out.println("Item " + i + " = " + arr.getNumber(i));
}
Example #3:
This example shows how to create an Actionscript object to send to the client.
We want the client to receive an AS object like this:
var obj:Object = {}
obj.name = "King Arthur"
obj.from = "Camelot"
obj.age = 36
obj.roundTable = true
obj.weapons = ["sword","knife"]
Here's how we can create this object in Java:
ActionscriptObject ao = new ActionscriptObject();
ao.put("name", "King Arthur");
ao.put("from", "Camelot");
ao.putNumber("age", 36);
ao.putBool("roundTable", true);
// Create the array object
ActionscriptObject ao_arr = new ActionscriptObject();
ao_arr.put(0, "sword");
ao_arr.put(1, "knife");
// Add the array in the main object
ao.put("weapons", ao_arr);
| Constructor Summary | |
|---|---|
ActionscriptObject()
Default constructor |
|
ActionscriptObject(java.util.Collection collection)
Constructs the ActionscriptObject populating it with the passed collection |
|
ActionscriptObject(DataRow row)
Constructs the ActionscriptObject populating it with the passed data row |
|
ActionscriptObject(java.util.Map map)
Constructs the ActionscriptObject populating it with the passed map |
|
| Method Summary | |
|---|---|
java.lang.Object |
get(int key)
Get an object from an index key |
java.lang.Object |
get(java.lang.String key)
Get an object from a string key |
boolean |
getBool(int key)
Get a boolean from an index key |
boolean |
getBool(java.lang.String key)
Get a boolean from a String key |
double |
getNumber(int key)
Get a number from an index key |
double |
getNumber(java.lang.String key)
Get a number from a string key |
ActionscriptObject |
getObj(int key)
Get an ActionscriptObject from an index key |
ActionscriptObject |
getObj(java.lang.String key)
Get an ActionscriptObject from a string key |
java.lang.String |
getString(int key)
Get a String from and index key |
java.lang.String |
getString(java.lang.String key)
Get a String from a string key |
java.util.Set |
keySet()
Get a Set of keys |
void |
put(int key,
java.lang.Object o)
Put an object with a numeric key (Indexed Array) |
void |
put(java.lang.String key,
java.lang.Object o)
Put an object with a String key (Associative Array) |
void |
putBool(int key,
boolean b)
Put a Boolean value with a numeric key (Indexed Array) |
void |
putBool(java.lang.String key,
boolean b)
Put a Boolean value with a string key (Indexed Array) |
void |
putCollection(int key,
java.util.Collection collection)
Adds the content of a Collection, which may also include other collections or maps |
void |
putCollection(java.lang.String key,
java.util.Collection collection)
Adds the content of a Collection, which may also include other collections or maps |
void |
putDataRow(int key,
DataRow row)
Add a DataRow coming from a database result set |
void |
putDataRow(java.lang.String key,
DataRow row)
Add a DataRow coming from a database result set |
void |
putMap(int key,
java.util.Map map)
Add the content of a Map, which can also contain other maps or collections |
void |
putMap(java.lang.String key,
java.util.Map map)
Add the content of a Map, which can also contain other maps or collections |
void |
putNumber(int key,
double d)
Put a Number with a numeric key (Indexed Array) |
void |
putNumber(java.lang.String key,
double d)
Put a Number with a string key (Associative Array) |
java.lang.Object |
removeElement(int key)
Remove an element |
java.lang.Object |
removeElement(java.lang.String key)
Remove an element |
int |
size()
Get the current number of elements |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ActionscriptObject()
public ActionscriptObject(java.util.Collection collection)
collection - a Collectionpublic ActionscriptObject(java.util.Map map)
map - a Mappublic ActionscriptObject(DataRow row)
row - a DataRow| Method Detail |
|---|
public void put(java.lang.String key,
java.lang.Object o)
key - the string keyo - the object
public void put(int key,
java.lang.Object o)
key - the index keyo - the object
public void putNumber(int key,
double d)
key - the index keyd - the number (treated as double)
public void putNumber(java.lang.String key,
double d)
key - the string keyd - the number (treated as double)
public void putBool(int key,
boolean b)
key - the index keyb - the boolean
public void putBool(java.lang.String key,
boolean b)
key - the string keyb - the booleanpublic java.lang.Object get(java.lang.String key)
key - the string key
public java.lang.Object get(int key)
key - the key
public java.lang.String getString(int key)
key - the key
public java.lang.String getString(java.lang.String key)
key - the key
public double getNumber(int key)
key - the key
public double getNumber(java.lang.String key)
key - the key
public boolean getBool(int key)
key - the key
public boolean getBool(java.lang.String key)
key - the key
public ActionscriptObject getObj(int key)
key - the index key
public ActionscriptObject getObj(java.lang.String key)
key - the key
public int size()
public java.util.Set keySet()
public java.lang.Object removeElement(int key)
key - the index key
public java.lang.Object removeElement(java.lang.String key)
key - the string key
public void putCollection(java.lang.String key,
java.util.Collection collection)
key - the String keycollection - the Collection
public void putCollection(int key,
java.util.Collection collection)
key - the numeric keycollection - the Collection
public void putMap(java.lang.String key,
java.util.Map map)
key - the String keymap - the Map object
public void putMap(int key,
java.util.Map map)
key - the numeric keymap - the Map object
public void putDataRow(java.lang.String key,
DataRow row)
key - the string keyrow - the DataRow object
public void putDataRow(int key,
DataRow row)
key - the numeric keyrow - the DataRow object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||