Packagecom.whirled
Classpublic class EntityControl
InheritanceEntityControl Inheritance AbstractControl Inheritance flash.events.EventDispatcher
SubclassesActorControl, FurniControl

Handles services that are available to all entities in a room. This includes dispatching trigger events and maintaining memory.



Protected Properties
 PropertyDefined by
  _env : String
The environment in which we're running.
EntityControl
Public Methods
 MethodDefined by
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener.
AbstractControl
  
canManageRoom(memberId:int = 0):Boolean
Returns true if the local client has management privileges in the current room.
EntityControl
  
clearPopup():void
Clear any showing popup.
EntityControl
 Inherited
doBatch(fn:Function, ... args):void
Execute the specified function as a batch of commands that will be sent to the server together.
AbstractControl
  
getCamera(index:String = null):Camera
Access the local user's camera.
EntityControl
  
getDefaultDataPack():ByteArray
Get the default datapack for this entity, or null if there is none defined.
EntityControl
  
getEntityIds(type:String = null):Array
Enumerates the ids of all entities in this room.
EntityControl
  
getEntityProperty(key:String, entityId:String = null):Object
Looks up and returns the specified property for the specified entity.
EntityControl
  
getEnvironment():String
Get the "environment" in which this entity is presently running.
EntityControl
  
Get the id of the viewer that is viewing this instance.
EntityControl
  
Returns our current logical location in the scene.
EntityControl
  
getMemories():Object
Return an associative hash of all the memories.
EntityControl
  
getMemory(key:String, defval:Object = null):Object
Returns the value associated with the supplied key in this item's memory.
EntityControl
  
getMicrophone(index:int = -1):Microphone
Access the local user's microphone.
EntityControl
  
getMusicId3():Object
Get the id3 metadata of the currently playing music.
EntityControl
  
Get the playerId of the owner of the currently playing music, aka the player who added it to the playlist, or 0 if there is no music currently playing.
EntityControl
  
getMyEntityId():String
Returns the Whirled-wide unique ID of this copy of the entity.
EntityControl
  
Returns our current location in the scene, in pixel coordinates.
EntityControl
  
getRoomBounds():Array
Get the room's bounds in pixels.
EntityControl
  
getViewerName(id:int = 0):String
Get the non-unique display name of the user viewing a particular instance.
EntityControl
  
hasControl():Boolean
Detects whether this client is in control.
EntityControl
 Inherited
isConnected():Boolean
Are we connected and running inside the whirled environment, or has someone just loaded up our SWF by itself?
AbstractControl
  
registerCustomConfig(func:Function):void
Register a function used for generating a custom config panel.
EntityControl
  
registerPropertyProvider(func:Function):void
Registers a function that provides custom entity properties.
EntityControl
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Unregisters an event listener.
AbstractControl
  
sendMessage(name:String, arg:Object = null):void
Send a message to other instances of this entity, resulting in a MESSAGE_RECEIVED event.
EntityControl
  
sendSignal(name:String, arg:Object = null):void
Send a message to all instances of all entities in this instance's current room, resulting in a SIGNAL_RECEIVED event.
EntityControl
  
setHotSpot(x:Number, y:Number, height:Number):void
Set the layout "hotspot" for your item, specified as pixels relative to (0, 0) the top-left coordinate.
EntityControl
  
setMemory(key:String, value:Object, callback:Function = null):void
Requests that this item's memory be updated with the supplied key/value pair.
EntityControl
  
setTickInterval(interval:Number):void
Configures the interval on which this item is "ticked" in milliseconds.
EntityControl
  
showPopup(title:String, panel:DisplayObject, width:Number, height:Number, backgroundColor:uint = 0xFFFFFF, backgroundAlpha:Number = 1.0):Boolean
Show a popup to the current user in the whirled.
EntityControl
  
triggerAction(name:String, arg:Object = null):void
Triggers an action on this scene object.
EntityControl
Events
 EventSummaryDefined by
   Dispatched when the instance in control sends a trigger action to all instances.EntityControl
   Dispatched to entities when they overhear chatter in the room.EntityControl
   Dispatched when this instance gains control.EntityControl
   Dispatched when an entity enters the room.EntityControl
   Dispatched when an entity leaves the room.EntityControl
   Dispatched when an entity in the room (other than the listening entity) changes location.EntityControl
   Dispatched when the instance in control updates the memory of this digital item.EntityControl
   Dispatched when any instance sends a message to all instances.EntityControl
   Dispatched when id3 data is found in the currently playing song.EntityControl
   Dispatched when music starts playing in the room.EntityControl
   Dispatched when music stops playing in the room.EntityControl
   Dispatched when any entity or AVR game sends a message to all other entities.EntityControl
   Dispatched once per tick, only when this instance has control and only if tick interval is registered.EntityControl
 Inherited Event.UNLOAD Dispatched when the SWF using this control has been unloaded.AbstractControl
Public Constants
 ConstantDefined by
  ENV_ROOM : String = "room"
[static] A constant returned by getEnvironment() to indicate that this entity is being viewed in a room.
EntityControl
  ENV_SHOP : String = "shop"
[static] A constant returned by getEnvironment() to indicate that this entity is being viewed in the shop.
EntityControl
  ENV_VIEWER : String = "viewer"
[static] A constant returned by getEnvironment() to indicate that this entity is being viewed in the "viewer": memories may be set and read, but they will not be saved.
EntityControl
  PROP_DIMENSIONS : String = "std:dimensions"
[static] The entity pixel dimensions (an Array [width, height]).
EntityControl
  PROP_HOTSPOT : String = "std:hotspot"
[static] The entity's hot spot (an Array [x, y]).
EntityControl
  PROP_LOCATION_LOGICAL : String = "std:location_logical"
[static] The entity's location in logical coordinates (an Array [ x, y, z ]).
EntityControl
  PROP_LOCATION_PIXEL : String = "std:location_pixel"
[static] The entity's location in pixel coordinates (an Array [ x, y, z ]).
EntityControl
  PROP_MEMBER_ID : String = "std:member_id"
[static] The unique Whirled player ID (int) of the wearer of the avatar, or the owner of the pet.
EntityControl
  PROP_MOVE_SPEED : String = "std:move_speed"
[static] The current movement speed of an actor (Number).
EntityControl
  PROP_NAME : String = "std:name"
[static] The non-unique display name of the entity (a String).
EntityControl
  PROP_ORIENTATION : String = "std:orientation"
[static] The entity facing direction (a Number).
EntityControl
  PROP_TYPE : String = "std:type"
[static] The type of the entity, TYPE_AVATAR, TYPE_PET or TYPE_FURNI.
EntityControl
  TYPE_AVATAR : String = "avatar"
[static] The type of avatar entities.
EntityControl
  TYPE_FURNI : String = "furni"
[static] The type of furniture entities.
EntityControl
  TYPE_PET : String = "pet"
[static] The type of pet entities.
EntityControl
Property detail
_envproperty
protected var _env:String

The environment in which we're running.

Method detail
canManageRoom()method
public function canManageRoom(memberId:int = 0):Boolean

Returns true if the local client has management privileges in the current room. A user with management permissions can edit the room, among other things. Passing 0 for the memberId indicates that this instance's viewing user should be checked. Note that this may change without notice, meaning that you shouldn't just check it once for a user and assume they still have management permissions later.

Parameters
memberId:int (default = 0)

Returns
Boolean
clearPopup()method 
public function clearPopup():void

Clear any showing popup. May be called at any time.

getCamera()method 
public function getCamera(index:String = null):Camera

Access the local user's camera.

Calling Camera.getCamera() does not work inside whirled due to security restrictions. For convenience, this method works even when you're not connected.

Parameters
index:String (default = null)

Returns
Camera
getDefaultDataPack()method 
public function getDefaultDataPack():ByteArray

Get the default datapack for this entity, or null if there is none defined. The DataPack is returned as a ByteArray, which can easily be passed to the com.whirled.DataPack constructor. We do not return a DataPack for you, because otherwise including this class would include all the DataPack support classes, even if your project never made use of it.

Returns
ByteArray
getEntityIds()method 
public function getEntityIds(type:String = null):Array

Enumerates the ids of all entities in this room.

Parameters
type:String (default = null) — an optional filter to restrict the results to a particular type of entity.

Returns
Array
getEntityProperty()method 
public function getEntityProperty(key:String, entityId:String = null):Object

Looks up and returns the specified property for the specified entity. Returns null if the entity does not exist or the entity has no such property.

Parameters
key:String
 
entityId:String (default = null)

Returns
Object
getEnvironment()method 
public function getEnvironment():String

Get the "environment" in which this entity is presently running.

Returns
String — one of the ENV_VIEWER, ENV_SHOP, or ENV_ROOM constants, or null if we're not connected.
getInstanceId()method 
public function getInstanceId():int

Get the id of the viewer that is viewing this instance. An instance is the copy of the entity running in a particular user's browser. If you are in a room with 2 other people, each piece of furniture has three instances: one on each person's browser.

Returns
int — the memberId of the player viewing this instance, or zero if the instance is being viewed by something other than a player.
getLogicalLocation()method 
public function getLogicalLocation():Array

Returns our current logical location in the scene. Note that if y is nonzero, you are flying. If applicable, an avatar should animate appropriately. The actor method isMoving() may return true or false when flying, depending on whether you're floating or actually moving between locations.

Returns
Array — an array containing [ x, y, z ]. x, y, and z are Numbers between 0 and 1 or null if our location is unknown.

See also

getMemories()method 
public function getMemories():Object

Return an associative hash of all the memories. This is not a cheap operation. Use getMemory if you know what you want.

Returns
Object

See also

getMemory()method 
public function getMemory(key:String, defval:Object = null):Object

Returns the value associated with the supplied key in this item's memory. If no value is mapped in the item's memory, the supplied default value will be returned.

Parameters
key:String
 
defval:Object (default = null)

Returns
Object — the value for the specified key from this item's memory or the supplied default.
getMicrophone()method 
public function getMicrophone(index:int = -1):Microphone

Access the local user's microphone.

Calling Microphone.getMicrophone() does not work inside whirled due to security restrictions. For convenience, this method works even when you're not connected.

Parameters
index:int (default = -1)

Returns
Microphone
getMusicId3()method 
public function getMusicId3():Object

Get the id3 metadata of the currently playing music. This will be an Object roughly in the format of flash.media.Id3Info, except that only the "raw" names of id3 tags are supported. http://www.id3.org

Returns
Object
getMusicOwnerId()method 
public function getMusicOwnerId():int

Get the playerId of the owner of the currently playing music, aka the player who added it to the playlist, or 0 if there is no music currently playing.

Returns
int
getMyEntityId()method 
public function getMyEntityId():String

Returns the Whirled-wide unique ID of this copy of the entity. Multiple copies of the same avatar in a room, for example, each have different entity IDs.

Returns
String
getPixelLocation()method 
public function getPixelLocation():Array

Returns our current location in the scene, in pixel coordinates.

Returns
Array — an array containing [ x, y, z ] in pixel coordinates. Obviously there is not a real Z coordinate, but the value will coorrespond to real Z distance in proportion to the distance in X and Y.
getRoomBounds()method 
public function getRoomBounds():Array

Get the room's bounds in pixels.

Returns
Array — an array containing [ width, height, depth ].
getViewerName()method 
public function getViewerName(id:int = 0):String

Get the non-unique display name of the user viewing a particular instance. Note that this cannot be used to look up member names of people who are not in the room.

TODO: other examples of where the member id comes from.

Parameters
id:int (default = 0) — a memberId, for example one obtained from getInstanceId. If the default argument of zero is passed, the instance id is used.

Returns
String — a String or null if the viewer is unknown.
hasControl()method 
public function hasControl():Boolean

Detects whether this client is in control.

Control is a mutually exclusive lock across all instances of the entity (i.e. running in other browsers across the network). Only one client can hold the lock at any time.

Returns
Boolean
registerCustomConfig()method 
public function registerCustomConfig(func:Function):void

Register a function used for generating a custom config panel. This will be called when this piece of furniture is being edited inside whirled.

Parameters
func:Function — signature: function () :DisplayObject

Your function should return a DisplayObject as a configuration panel. The width/height of the object at return time will be used to configure the amount of space given it. Any changes made by the user should effect immediately, or you should provide buttons to apply the change, if absolutely necessary.

registerPropertyProvider()method 
public function registerPropertyProvider(func:Function):void

Registers a function that provides custom entity properties. This should be done immediately after creating your EntityControl, for example:

     var ctrl :FurniControl = new FurniControl(this);
     ctrl.registerPropertyProvider(getEntityProperty);
     

Parameters
func:Function — signature: function (key :String) :Object
sendMessage()method 
public function sendMessage(name:String, arg:Object = null):void

Send a message to other instances of this entity, resulting in a MESSAGE_RECEIVED event.

Note: the name must be a String and may be up to 64 characters. The argument may be up to 1024 bytes after being AMF3 encoded.

Note: Any instance can send messages. Compare with triggerAction.

Parameters
name:String
 
arg:Object (default = null)
sendSignal()method 
public function sendSignal(name:String, arg:Object = null):void

Send a message to all instances of all entities in this instance's current room, resulting in a SIGNAL_RECEIVED event. All instances of the entity can initiate a signal, so the user must take care to check for control when appropriate.

Note: the name must be a String and may be up to 64 characters. The argument may be up to 1024 bytes after being AMF3 encoded.

Parameters
name:String
 
arg:Object (default = null)
setHotSpot()method 
public function setHotSpot(x:Number, y:Number, height:Number):void

Set the layout "hotspot" for your item, specified as pixels relative to (0, 0) the top-left coordinate. If unset, the default hotspot will be based off of the SWF dimensions, with x = width / 2, y = height.

Parameters
x:Number — the new hotspot x coordinate
 
y:Number — the new hotspot y coordinate
 
height:Number — if specified, the entity's actual current height, as pixels above the hotspot. This is used by avatars to position the name label.
setMemory()method 
public function setMemory(key:String, value:Object, callback:Function = null):void

Requests that this item's memory be updated with the supplied key/value pair. The supplied value must be a simple object (Integer, Number, String) or an Array of simple objects. The contents of the entity's memory (keys and values) must not exceed 4096 bytes when AMF3 encoded.

Setting the memory for a key to null clears that key; subsequent lookups will return the default value.

Note: for avatars, only the instance "in control" can update memories, but this restriction does not hold (presently) for pets, furni, toys, or backdrops. Put another way, only the instance of the person wearing the avatar can update memories.

Parameters
key:String — An optional function that is passed a Boolean indicating whether the memory was successfully updated or not. True if the memory update was accepted, or false if the memory update failed due to size or other restrictions.
 
value:Object
 
callback:Function (default = null)
setTickInterval()method 
public function setTickInterval(interval:Number):void

Configures the interval on which this item is "ticked" in milliseconds. If the client setting this interval is in control, it will get a timer event at the specified interval.

Ticking mechanism is turned off by default. Application needs to set the interval explicitly to start receiving tick events. The tick interval can be no smaller than 100ms to avoid bogging down the client.

Parameters
interval:Number — Delay between ticks in milliseconds, either 0ms, or a value larger than 100ms. Value larger than zero activates the ticking mechanism, and a value of exactly zero deactivates it.
showPopup()method 
public function showPopup(title:String, panel:DisplayObject, width:Number, height:Number, backgroundColor:uint = 0xFFFFFF, backgroundAlpha:Number = 1.0):Boolean

Show a popup to the current user in the whirled. Only one popup between all entities in a room can be show at one time. Calling this closes any existing popup currently open.

Parameters
title:String — The title displayed in the title bar for the popup.
 
panel:DisplayObject — The display object to show in the popup. It should only paint inside the rectangle defined by (0, 0, width, height).
 
width:Number — The width of the panel.
 
height:Number — The height of the panel.
 
backgroundColor:uint (default = 0xFFFFFF) — The RGB value to fill the background of the panel with.
 
backgroundAlpha:Number (default = 1.0) — The transparency to fill the background of the panel with.

Returns
Boolean — true if the popup was shown, false if it could not be shown for various reasons.
triggerAction()method 
public function triggerAction(name:String, arg:Object = null):void

Triggers an action on this scene object. The action will be properly distributed to the object running in every client in the scene, resulting in a ACTION_TRIGGERED event.

Note: the name must be a String and may be up to 64 characters. The argument may be up to 1024 bytes after being AMF3 encoded.

Note: Only the instance "in control" can trigger actions. If you want any instance to be able to communicate, use sendMessage().

Parameters
name:String
 
arg:Object (default = null)
Event detail
actionTriggeredevent 
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.ACTION_TRIGGERED

Dispatched when the instance in control sends a trigger action to all instances.

An event type dispatched when an action is triggered.
name - action name
value - action value

chatReceivedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.CHAT_RECEIVED

Dispatched to entities when they overhear chatter in the room. Only the instance in control receives this event.

An event type dispatched to all entities when someone chats. Note that only the instance in control receives this event.
name - the speaker's entity ID
value - chat message

controlAcquiredevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.CONTROL_ACQUIRED

Dispatched when this instance gains control. See the hasControl method.

An event type dispatched when this client-side instance of the item has gained "control" over the other client-side instances.
name - unused
value - unused

entityEnteredevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.ENTITY_ENTERED

Dispatched when an entity enters the room.

An event dispatched when a new entity has been added to the room. Note: only the instance in control receives this event.
name - The new entity ID
value - unused

entityLeftevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.ENTITY_LEFT

Dispatched when an entity leaves the room.

An event dispatched when an entity has been removed from the room. Note: only the instance in control receives this event.
name - The entity ID. Note that this will no longer exist in the room.
value - unused

entityMovedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.ENTITY_MOVED

Dispatched when an entity in the room (other than the listening entity) changes location.

An event dispatched when an actor begins and ends walking within the room. Note: only the instance in control receives this event.
name - The moving entity's ID
value - If the actor has started moving, this is an array containing the logical location it is moving to. Null when this event fires in response to the actor arriving at its destination.

memoryChangedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.MEMORY_CHANGED

Dispatched when the instance in control updates the memory of this digital item.

An event type dispatched when the memory has changed.
name - memory name
value - memory value

messageReceivedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.MESSAGE_RECEIVED

Dispatched when any instance sends a message to all instances.

An event type dispatched when a message is received.
name - message name
value - message value

musicId3event  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.MUSIC_ID3

Dispatched when id3 data is found in the currently playing song. Apparently many mp3 files contain both 2.id3 data, near the beginning of the file, and 1.data, found at the end, and so flash dispatches each set of data as it finds it. And we just pass it along to you.

An event that may be dispatched soon after music starts playing.
name - unused
value - an Object from which id3 tags may be read.

musicStartedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.MUSIC_STARTED

Dispatched when music starts playing in the room. If the current user can hear it, id3 data aybe available shortly after this event. The sequence of events goes like this: MUSIC_STARTED, 0 or more MUSIC_ID3 tags, MUSIC_STOPPED. Note however that you may not get a MUSIC_STARTED event if the music starts playing prior to your entity initializing. Calling getMusicOwnerId() can tell you definitively if there is music currently playing.

An event dispatched when some music starts playing.
name - unused
value - unused

musicStoppedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.MUSIC_STOPPED

Dispatched when music stops playing in the room.

An event dispatched when some music stops playing.
name - unused
value - unused

See also

signalReceivedevent  
Event object type: com.whirled.ControlEvent
ControlEvent.type property = com.whirled.ControlEvent.SIGNAL_RECEIVED

Dispatched when any entity or AVR game sends a message to all other entities.

Note: this is only dispatched to the instance in control.

An event type dispatched when a signal is received. Dispatched only to the instance in control.
name - signal name
value - signal value

See also

timerevent  
Event object type: flash.events.TimerEvent

Dispatched once per tick, only when this instance has control and only if tick interval is registered.

Constant detail
ENV_ROOMconstant
public static const ENV_ROOM:String = "room"

A constant returned by getEnvironment() to indicate that this entity is being viewed in a room. Memories are persistent.

ENV_SHOPconstant 
public static const ENV_SHOP:String = "shop"

A constant returned by getEnvironment() to indicate that this entity is being viewed in the shop. If the user buys the item, any memories will be saved for the user's new copy of the item.

ENV_VIEWERconstant 
public static const ENV_VIEWER:String = "viewer"

A constant returned by getEnvironment() to indicate that this entity is being viewed in the "viewer": memories may be set and read, but they will not be saved.

PROP_DIMENSIONSconstant 
public static const PROP_DIMENSIONS:String = "std:dimensions"

The entity pixel dimensions (an Array [width, height]). Use with getEntityProperty().

PROP_HOTSPOTconstant 
public static const PROP_HOTSPOT:String = "std:hotspot"

The entity's hot spot (an Array [x, y]). Use with getEntityProperty().

PROP_LOCATION_LOGICALconstant 
public static const PROP_LOCATION_LOGICAL:String = "std:location_logical"

The entity's location in logical coordinates (an Array [ x, y, z ]). x, y, and z are Numbers between that are typically between 0 and 1 or null if our location is unknown. Note that Whirled allows furniture to be positioned "outside" the room, at locations less than 0 or greater than 1, in order to create a desired effect, so don't be surprised if something is placed at wacky coordinates. Use with getEntityProperty().

PROP_LOCATION_PIXELconstant 
public static const PROP_LOCATION_PIXEL:String = "std:location_pixel"

The entity's location in pixel coordinates (an Array [ x, y, z ]). Obviously there is not a real Z coordinate, but the value will coorrespond to real Z distance in proportion to the distance in X and Y. Use with getEntityProperty().

PROP_MEMBER_IDconstant 
public static const PROP_MEMBER_ID:String = "std:member_id"

The unique Whirled player ID (int) of the wearer of the avatar, or the owner of the pet. Use with getEntityProperty().

PROP_MOVE_SPEEDconstant 
public static const PROP_MOVE_SPEED:String = "std:move_speed"

The current movement speed of an actor (Number).

PROP_NAMEconstant 
public static const PROP_NAME:String = "std:name"

The non-unique display name of the entity (a String). Use with getEntityProperty(). Valid only for "avatar" and "pet" entity types. Invalid entity types will return null.

PROP_ORIENTATIONconstant 
public static const PROP_ORIENTATION:String = "std:orientation"

The entity facing direction (a Number). Use with getEntityProperty(). Valid only for "avatar" and "pet" entity types.

PROP_TYPEconstant 
public static const PROP_TYPE:String = "std:type"

The type of the entity, TYPE_AVATAR, TYPE_PET or TYPE_FURNI. Use with getEntityProperty().

TYPE_AVATARconstant 
public static const TYPE_AVATAR:String = "avatar"

The type of avatar entities.

TYPE_FURNIconstant 
public static const TYPE_FURNI:String = "furni"

The type of furniture entities.

TYPE_PETconstant 
public static const TYPE_PET:String = "pet"

The type of pet entities.