it.gotoandplay.smartfoxserver.lib
Class ActionscriptObject

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.lib.ActionscriptObject

public class ActionscriptObject
extends java.lang.Object

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
 
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 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

ActionscriptObject

public ActionscriptObject()
Default constructor

Method Detail

put

public void put(java.lang.String key,
                java.lang.Object o)
Put an object with a String key (Associative Array)

Parameters:
key - the string key
o - the object

put

public void put(int key,
                java.lang.Object o)
Put an object with a numeric key (Indexed Array)

Parameters:
key - the index key
o - the object

putNumber

public void putNumber(int key,
                      double d)
Put a Number with a numeric key (Indexed Array)

Parameters:
key - the index key
d - the number (treated as double)

putNumber

public void putNumber(java.lang.String key,
                      double d)
Put a Number with a string key (Associative Array)

Parameters:
key - the string key
d - the number (treated as double)

putBool

public void putBool(int key,
                    boolean b)
Put a Boolean value with a numeric key (Indexed Array)

Parameters:
key - the index key
b - the boolean

putBool

public void putBool(java.lang.String key,
                    boolean b)
Put a Boolean value with a string key (Indexed Array)

Parameters:
key - the string key
b - the boolean

get

public java.lang.Object get(java.lang.String key)
Get an object from a string key

Parameters:
key - the string key
Returns:
the object

get

public java.lang.Object get(int key)
Get an object from an index key

Parameters:
key - the key
Returns:
the object

getString

public java.lang.String getString(int key)
Get a String from and index key

Parameters:
key - the key
Returns:
the string

getString

public java.lang.String getString(java.lang.String key)
Get a String from a string key

Parameters:
key - the key
Returns:
the string

getNumber

public double getNumber(int key)
Get a number from an index key

Parameters:
key - the key
Returns:
the number (as double)

getNumber

public double getNumber(java.lang.String key)
Get a number from a string key

Parameters:
key - the key
Returns:
the number (as double)

getBool

public boolean getBool(int key)
Get a boolean from an index key

Parameters:
key - the key
Returns:
the boolean

getBool

public boolean getBool(java.lang.String key)
Get a boolean from a String key

Parameters:
key - the key
Returns:
the boolean

getObj

public ActionscriptObject getObj(int key)
Get an ActionscriptObject from an index key

Parameters:
key - the index key
Returns:
the ActionscriptObject

getObj

public ActionscriptObject getObj(java.lang.String key)
Get an ActionscriptObject from a string key

Parameters:
key - the key
Returns:
the ActionscriptObject

size

public int size()
Get the current number of elements

Returns:
the current size

keySet

public java.util.Set keySet()
Get a Set of keys

Returns:
the key set

removeElement

public java.lang.Object removeElement(int key)
Remove an element

Parameters:
key - the index key
Returns:
the element removed

removeElement

public java.lang.Object removeElement(java.lang.String key)
Remove an element

Parameters:
key - the string key
Returns:
the element removed