Packagecom.pblabs.engine
Classpublic class PBE
InheritancePBE Inheritance Object

Utility class to simplify working with PushButton Engine. This class makes some assumptions about what components and modules are present. If you are doing strange things, then you may need to directly access things this class does for you. However if you are just getting started this is likely to be a useful toolkit.



Public Properties
 PropertyDefined By
  currentGroup : PBGroup
[static] PBObjects are automatically added to the currentGroup when they are created, so that nothing is every unrooted in the PBObject tree.
PBE
  inputManager : InputManager
[static] [read-only] Returns the InputManager instance.
PBE
  IS_SHIPPING_BUILD : Boolean = false
[static] Set this to true to get rid of a bunch of development related functionality that isn't needed in a final release build.
PBE
  levelManager : LevelManager
[static] [read-only] Returns the LevelManager instance
PBE
  mainClass : Sprite
[static] [read-only] A reference to the main class of the application.
PBE
  mainStage : Stage
[static] [read-only] The stage.
PBE
  nameManager : NameManager
[static] [read-only] Returns the NameManager instance
PBE
  objectTypeManager : ObjectTypeManager
[static] [read-only] Returns the ObjectTypeManager instance.
PBE
  processManager : ProcessManager
[static] [read-only] Returns the ProcessManager instance
PBE
  resourceManager : ResourceManager
[static] [read-only] Returns the ResourceManager instance.
PBE
  rootGroup : PBGroup
[static] [read-only] The root group; all sets and groups should be ultimately owned by this guy.
PBE
  scene : IScene2D
[static] [read-only]
PBE
  screenManager : ScreenManager
[static] [read-only] Returns the ScreenManager instance
PBE
  soundManager : ISoundManager
[static] [read-only] Returns the global SoundManager instance.
PBE
  spatialManager : ISpatialManager2D
[static] [read-only]
PBE
  started : Boolean
[static] [read-only] True if PBE.startup has been called.
PBE
  templateManager : TemplateManager
[static] [read-only] Returns the TemplateManager instance.
PBE
  versionDetails : VersionDetails
[static] [read-only] Returns information about the current running swf.
PBE
Protected Properties
 PropertyDefined By
  _currentGroup : PBGroup = null
[static]
PBE
  _inputManager : InputManager = null
[static]
PBE
  _nameManager : NameManager = null
[static]
PBE
  _objectTypeManager : ObjectTypeManager = null
[static]
PBE
  _processManager : ProcessManager = null
[static]
PBE
  _resourceManager : ResourceManager = null
[static]
PBE
  _rootGroup : PBGroup = null
[static]
PBE
  _scene : DisplayObjectScene
[static]
PBE
  _soundManager : SoundManager = null
[static]
PBE
  _spatialManager : ISpatialManager2D
[static]
PBE
  _templateManager : TemplateManager = null
[static]
PBE
Public Methods
 MethodDefined By
  
[static] If you want to use a ResourceBundle, add it to PBE with this method.
PBE
  
[static] Allocates an instance of the hidden Entity class.
PBE
  
callLater(method:Function, args:Array = null):void
[static] Defer a call until the start of the next tick or frame.
PBE
  
defineEntityByFunction(name:String, definition:Function):void
[static] Define an entity using a function callback.
PBE
  
defineWithXML(xml:XML):void
[static] Define one or more entities using PBE level XML.
PBE
  
findChild(name:String, displayObjectToSearch:DisplayObject = null):DisplayObject
[static] Recursively searches for an object with the specified name that has been added to the display hierarchy.
PBE
  
getFlashVars():Object
[static]
PBE
  
[static]
PBE
  
getRegisteredTypes():Dictionary
[static]
PBE
  
initializeScene(view:IUITarget, sceneName:String = SceneDB, sceneClass:Class = null, spatialManagerClass:Class = null, sceneAlignment:SceneAlignment = null):IEntity
[static] Helper function to set up a basic scene using default Rendering2D classes.
PBE
  
isAnyKeyDown():Boolean
[static] Return true if any key is down.
PBE
  
isKeyDown(key:InputKey):Boolean
[static] Return true if the specified key is down.
PBE
  
loadResource(filename:String, resourceType:Class, onLoaded:Function = null, onFailed:Function = null, forceReload:Boolean = false):void
[static] Loads a resource from a file.
PBE
  
log(reporter:*, message:String):void
[static] Print a message to the log.
PBE
  
lookup(objectName:String):PBObject
[static] Locate a PBObject (entity, set, group) by its name.
PBE
  
lookupComponentByName(entityName:String, componentName:String):IEntityComponent
[static] Locate a named component on a named entity.
PBE
  
lookupComponentByType(entityName:String, componentType:Class):IEntityComponent
[static] Locate the first component of a type on a named entity.
PBE
  
lookupEntity(entityName:String):IEntity
[static] Locate an IEntity by its name.
PBE
  
makeEntity(entityName:String, params:Object = null):IEntity
[static] Make a new instance of an entity, setting appropriate fields based on the parameters passed.
PBE
  
[static] Restore stage quality to previous value.
PBE
  
pushStageQuality(newQuality:String):void
[static] Set stage quality to a new value, and store the old value so we can restore it later.
PBE
  
registerType(type:Class):void
[static] Register a type with PushButton Engine so that it can be deserialized, even if no code directly uses it.
PBE
  
startup(mainClass:Sprite):void
[static] Start the engine by giving it a reference to the root of the display hierarchy.
PBE
Protected Methods
 MethodDefined By
  
[static]
PBE
Property Detail
_currentGroupproperty
protected static var _currentGroup:PBGroup = null

_inputManagerproperty 
protected static var _inputManager:InputManager = null

_nameManagerproperty 
protected static var _nameManager:NameManager = null

_objectTypeManagerproperty 
protected static var _objectTypeManager:ObjectTypeManager = null

_processManagerproperty 
protected static var _processManager:ProcessManager = null

_resourceManagerproperty 
protected static var _resourceManager:ResourceManager = null

_rootGroupproperty 
protected static var _rootGroup:PBGroup = null

_sceneproperty 
protected static var _scene:DisplayObjectScene

_soundManagerproperty 
protected static var _soundManager:SoundManager = null

_spatialManagerproperty 
protected static var _spatialManager:ISpatialManager2D

_templateManagerproperty 
protected static var _templateManager:TemplateManager = null

currentGroupproperty 
currentGroup:PBGroup

PBObjects are automatically added to the currentGroup when they are created, so that nothing is every unrooted in the PBObject tree. You can set this to whatever you like.


Implementation
    public static function get currentGroup():PBGroup
    public static function set currentGroup(value:PBGroup):void
inputManagerproperty 
inputManager:InputManager  [read-only]

Returns the InputManager instance.


Implementation
    public static function get inputManager():InputManager
IS_SHIPPING_BUILDproperty 
public static var IS_SHIPPING_BUILD:Boolean = false

Set this to true to get rid of a bunch of development related functionality that isn't needed in a final release build.

levelManagerproperty 
levelManager:LevelManager  [read-only]

Returns the LevelManager instance


Implementation
    public static function get levelManager():LevelManager
mainClassproperty 
mainClass:Sprite  [read-only]

A reference to the main class of the application. This must be set when the application first loads as several core subsystems rely on it's presence.


Implementation
    public static function get mainClass():Sprite
mainStageproperty 
mainStage:Stage  [read-only]

The stage. This is the root of the display heirarchy and is automatically created by flash when the application starts up.


Implementation
    public static function get mainStage():Stage
nameManagerproperty 
nameManager:NameManager  [read-only]

Returns the NameManager instance


Implementation
    public static function get nameManager():NameManager
objectTypeManagerproperty 
objectTypeManager:ObjectTypeManager  [read-only]

Returns the ObjectTypeManager instance.


Implementation
    public static function get objectTypeManager():ObjectTypeManager
processManagerproperty 
processManager:ProcessManager  [read-only]

Returns the ProcessManager instance


Implementation
    public static function get processManager():ProcessManager
resourceManagerproperty 
resourceManager:ResourceManager  [read-only]

Returns the ResourceManager instance.


Implementation
    public static function get resourceManager():ResourceManager
rootGroupproperty 
rootGroup:PBGroup  [read-only]

The root group; all sets and groups should be ultimately owned by this guy.


Implementation
    public static function get rootGroup():PBGroup
sceneproperty 
scene:IScene2D  [read-only]


Implementation
    public static function get scene():IScene2D
screenManagerproperty 
screenManager:ScreenManager  [read-only]

Returns the ScreenManager instance


Implementation
    public static function get screenManager():ScreenManager
soundManagerproperty 
soundManager:ISoundManager  [read-only]

Returns the global SoundManager instance.


Implementation
    public static function get soundManager():ISoundManager
spatialManagerproperty 
spatialManager:ISpatialManager2D  [read-only]


Implementation
    public static function get spatialManager():ISpatialManager2D
startedproperty 
started:Boolean  [read-only]

True if PBE.startup has been called.


Implementation
    public static function get started():Boolean
templateManagerproperty 
templateManager:TemplateManager  [read-only]

Returns the TemplateManager instance.


Implementation
    public static function get templateManager():TemplateManager
versionDetailsproperty 
versionDetails:VersionDetails  [read-only]

Returns information about the current running swf.


Implementation
    public static function get versionDetails():VersionDetails
Method Detail
addResources()method
public static function addResources(rb:ResourceBundle):void

If you want to use a ResourceBundle, add it to PBE with this method.

Parameters

rb:ResourceBundle

allocateEntity()method 
public static function allocateEntity():IEntity

Allocates an instance of the hidden Entity class. This should be used anytime an IEntity object needs to be created. Encapsulating the Entity class forces code to use IEntity rather than Entity when dealing with entity references. This will ensure that code is future proof as well as allow the Entity class to be pooled in the future.

Returns
IEntity — A new IEntity.
callLater()method 
public static function callLater(method:Function, args:Array = null):void

Defer a call until the start of the next tick or frame.

Parameters

method:Function — Method to call.
 
args:Array (default = null) — Arguments, if any.

defineEntityByFunction()method 
public static function defineEntityByFunction(name:String, definition:Function):void

Define an entity using a function callback.

Parameters

name:String — The name of the entity; used to identify it for creation later.
 
definition:Function — The function, taking no arguments and returning IEntity, which creates an instance of that entity.

defineWithXML()method 
public static function defineWithXML(xml:XML):void

Define one or more entities using PBE level XML. This function will do its best to cope with what you give it. It can accept either a things tag containing several entities/templates/groups, or a template or entity tag defining a single item.

Parameters

xml:XML

findChild()method 
public static function findChild(name:String, displayObjectToSearch:DisplayObject = null):DisplayObject

Recursively searches for an object with the specified name that has been added to the display hierarchy.

Parameters

name:String — The name of the object to find.
 
displayObjectToSearch:DisplayObject (default = null)

Returns
DisplayObject — The display object with the specified name, or null if it wasn't found.
getFlashVars()method 
public static function getFlashVars():Object

Returns
Object
getHostingDomain()method 
public static function getHostingDomain():String

Returns
String
getRegisteredTypes()method 
public static function getRegisteredTypes():Dictionary

Returns
Dictionary — A dictionary of Registered types. With keys as class names and values as class definitions
initializeManagers()method 
protected static function initializeManagers():void

initializeScene()method 
public static function initializeScene(view:IUITarget, sceneName:String = SceneDB, sceneClass:Class = null, spatialManagerClass:Class = null, sceneAlignment:SceneAlignment = null):IEntity

Helper function to set up a basic scene using default Rendering2D classes. Very useful for getting started quickly.

Parameters

view:IUITarget
 
sceneName:String (default = SceneDB)
 
sceneClass:Class (default = null)
 
spatialManagerClass:Class (default = null)
 
sceneAlignment:SceneAlignment (default = null)

Returns
IEntity
isAnyKeyDown()method 
public static function isAnyKeyDown():Boolean

Return true if any key is down.

Returns
Boolean
isKeyDown()method 
public static function isKeyDown(key:InputKey):Boolean

Return true if the specified key is down.

Parameters

key:InputKey

Returns
Boolean
loadResource()method 
public static function loadResource(filename:String, resourceType:Class, onLoaded:Function = null, onFailed:Function = null, forceReload:Boolean = false):void

Loads a resource from a file. If the resource has already been loaded or is embedded, a reference to the existing resource will be given. The resource is not returned directly since loading is asynchronous. Instead, it will be passed to the function specified in the onLoaded parameter. Even if the resource has already been loaded, it cannot be assumed that the callback will happen synchronously.

This will not attempt to load resources that have previously failed to load. Instead, the load will fail instantly.

Parameters

filename:String — The url of the file to load.
 
resourceType:Class — The Resource subclass specifying the type of resource that is being requested.
 
onLoaded:Function (default = null) — A function that will be called on successful load of the resource. The function should take a single parameter of the type specified in the resourceType parameter.
 
onFailed:Function (default = null) — A function that will be called if loading of the resource fails. The function should take a single parameter of the type specified in the resourceType parameter. The resource passed to the function will be invalid, but the filename property will be correct.
 
forceReload:Boolean (default = false) — Always reload the resource, even if it has already been loaded.

See also

Resource
log()method 
public static function log(reporter:*, message:String):void

Print a message to the log.

Parameters

reporter:* — Usually 'this'; the class initiating the logging.
 
message:String — The message to log.

lookup()method 
public static function lookup(objectName:String):PBObject

Locate a PBObject (entity, set, group) by its name.

Parameters

objectName:String

Returns
PBObject
lookupComponentByName()method 
public static function lookupComponentByName(entityName:String, componentName:String):IEntityComponent

Locate a named component on a named entity.

Parameters

entityName:String
 
componentName:String

Returns
IEntityComponent
lookupComponentByType()method 
public static function lookupComponentByType(entityName:String, componentType:Class):IEntityComponent

Locate the first component of a type on a named entity.

Parameters

entityName:String
 
componentType:Class

Returns
IEntityComponent
lookupEntity()method 
public static function lookupEntity(entityName:String):IEntity

Locate an IEntity by its name.

Parameters

entityName:String

Returns
IEntity
makeEntity()method 
public static function makeEntity(entityName:String, params:Object = null):IEntity

Make a new instance of an entity, setting appropriate fields based on the parameters passed.

Parameters

entityName:String — Identifier by which to look up the entity on the TemplateManager.
 
params:Object (default = null) — Properties to assign, by key/value. Keys can be strings or PropertyReferences. Values can be any type.

Returns
IEntity
popStageQuality()method 
public static function popStageQuality():void

Restore stage quality to previous value.

See also

pushStageQuality
pushStageQuality()method 
public static function pushStageQuality(newQuality:String):void

Set stage quality to a new value, and store the old value so we can restore it later. Useful if you want to temporarily toggle render quality.

Parameters

newQuality:String — From StafeQuality, new quality level to use.

registerType()method 
public static function registerType(type:Class):void

Register a type with PushButton Engine so that it can be deserialized, even if no code directly uses it.

Parameters

type:Class

startup()method 
public static function startup(mainClass:Sprite):void

Start the engine by giving it a reference to the root of the display hierarchy.

Parameters

mainClass:Sprite