Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## it.gotoandplay.smartfoxserver.lib
Class ActionscriptObject

    java.lang.Object
      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:

- Numbers
- Strings
- Booleans
- Arrays
- Objects

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

Author:
  (c) 2004-2007 gotoAndPlay() -- www.gotoandplay.it

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

### ActionscriptObject

    public ActionscriptObject()

  Default constructor

### ActionscriptObject

    public ActionscriptObject(java.util.Collection collection)

  Constructs the ActionscriptObject populating it with the passed collection

  Parameters:
    `collection` - a Collection

### ActionscriptObject

    public ActionscriptObject(java.util.Map map)

  Constructs the ActionscriptObject populating it with the passed map

  Parameters:
    `map` - a Map

### ActionscriptObject

    public ActionscriptObject(DataRow row)

  Constructs the ActionscriptObject populating it with the passed data row

  Parameters:
    `row` - a DataRow

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

### putCollection

    public void putCollection(java.lang.String key,
                              java.util.Collection collection)

  Adds the content of a Collection, which may also include other collections or maps

  Parameters:
    `key` - the String key
    `collection` - the Collection
  Since:
    1.6.0

### putCollection

    public void putCollection(int key,
                              java.util.Collection collection)

  Adds the content of a Collection, which may also include other collections or maps

  Parameters:
    `key` - the numeric key
    `collection` - the Collection
  Since:
    1.6.0

### putMap

    public void putMap(java.lang.String key,
                       java.util.Map map)

  Add the content of a Map, which can also contain other maps or collections

  Parameters:
    `key` - the String key
    `map` - the Map object
  Since:
    1.6.0

### putMap

    public void putMap(int key,
                       java.util.Map map)

  Add the content of a Map, which can also contain other maps or collections

  Parameters:
    `key` - the numeric key
    `map` - the Map object
  Since:
    1.6.0

### putDataRow

    public void putDataRow(java.lang.String key,
                           DataRow row)

  Add a DataRow coming from a database result set

  Parameters:
    `key` - the string key
    `row` - the DataRow object
  Since:
    1.6.0

### putDataRow

    public void putDataRow(int key,
                           DataRow row)

  Add a DataRow coming from a database result set

  Parameters:
    `key` - the numeric key
    `row` - the DataRow object
  Since:
    1.6.0

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD