Packagecom.pblabs.engine.core
Classpublic class LevelManager
InheritanceLevelManager Inheritance flash.events.EventDispatcher
Implements ISerializable

The LevelManager allows level files and groups to be added to a specific level so they can be automatically managed when that level is loaded or unloaded.

See also

com.pblabs.engine.mxml.LevelFileReference
com.pblabs.engine.mxml.GroupReference


Public Properties
 PropertyDefined By
  currentLevel : int
[read-only] The level that is currently loaded.
LevelManager
  instance : LevelManager
[static] [read-only] The singleton LevelManager instance.
LevelManager
  levelCount : int
[read-only] Returns the number of levels the LevelManager has data for.
LevelManager
Public Methods
 MethodDefined By
  
addFileReference(index:int, filename:String):void
Register a file with a level number.
LevelManager
  
addGroupReference(index:int, name:String):void
Register a group with a level number.
LevelManager
  
clear():void
Unload the current level.
LevelManager
  
deserialize(xml:XML):*
deserializes the object from xml.
LevelManager
  
getLevelDescription(index:int):LevelDescription
LevelManager
  
getlevelFiles(index:int):Array
Gets an array of filenames that are to be loaded with a specific level.
LevelManager
  
getlevelGroups(index:int):Array
Gets an array of group names that are to be loaded with a specific level.
LevelManager
  
getlevelIndexByName(levelName:String):int
Gets a level index based on the registered level name.
LevelManager
  
load(filename:String, initialLevel:int = -1):void
Starts up the level manager and loads level description data from an xml file.
LevelManager
  
loadEntity(name:String):IEntity
Loads an entity with the TemplateManager and tracks it.
LevelManager
  
loadLevel(index:int, force:Boolean = false):void
Loads the specified level and unloads any previous levels.
LevelManager
  
Loads the next level after the current level.
LevelManager
  
removeFileReference(index:int, filename:String):void
Remove a file from a level number.
LevelManager
  
removeGroupReference(index:int, name:String):void
Remove a group from a level number.
LevelManager
  
removeLevel(index:int):void
Removes the level with the specified index.
LevelManager
  
serialize(xml:XML):void
serializes the object to XML.
LevelManager
  
setLoadFileCallbacks(load:Function, unload:Function):void
With this method, you can override the default file loading methods by having custom functions called instead of the defaults.
LevelManager
  
setLoadGroupCallbacks(load:Function, unload:Function):void
With this method, you can override the default group loading methods by having custom functions called instead of the defaults.
LevelManager
  
start(initialLevel:int = -1):void
Starts up the LevelManager.
LevelManager
  
Unloads all the currently loaded data.
LevelManager
Events
 Event Summary Defined By
   This event is dispatched by the LevelManager when a level's data has been loaded.LevelManager
   This event is dispatched by the LevelManager when a level's data has been unloaded.LevelManager
   This event is dispatched by the LevelManager when it is ready to be used.LevelManager
Property Detail
currentLevelproperty
currentLevel:int  [read-only]

The level that is currently loaded.


Implementation
    public function get currentLevel():int
instanceproperty 
instance:LevelManager  [read-only]

The singleton LevelManager instance.


Implementation
    public static function get instance():LevelManager
levelCountproperty 
levelCount:int  [read-only]

Returns the number of levels the LevelManager has data for.


Implementation
    public function get levelCount():int
Method Detail
addFileReference()method
public function addFileReference(index:int, filename:String):void

Register a file with a level number. The same file can be registered with several levels.

Parameters

index:int — The level to register with
 
filename:String — The file to register

addGroupReference()method 
public function addGroupReference(index:int, name:String):void

Register a group with a level number. The same group can be registered with several levels.

Parameters

index:int — The level to register with
 
name:String — The name of the group to register

clear()method 
public function clear():void

Unload the current level.

deserialize()method 
public function deserialize(xml:XML):*

deserializes the object from xml. The format of the xml passed is custom, depending on the way the object was serialized with the serialize method.

Parameters

xml:XML — The xml containing the serialized definition of the class.

Returns
* — The deserialized object. Usually 'this' should be returned, but in some cases it may be useful to return something else. The Enumerable class does this to force all values to be a member of the enumeration.
getLevelDescription()method 
public function getLevelDescription(index:int):LevelDescription

Parameters

index:int

Returns
LevelDescription
getlevelFiles()method 
public function getlevelFiles(index:int):Array

Gets an array of filenames that are to be loaded with a specific level.

Parameters

index:int

Returns
Array
getlevelGroups()method 
public function getlevelGroups(index:int):Array

Gets an array of group names that are to be loaded with a specific level.

Parameters

index:int

Returns
Array
getlevelIndexByName()method 
public function getlevelIndexByName(levelName:String):int

Gets a level index based on the registered level name. Case sensitive. Returns -1 if the level name is not found.

Parameters

levelName:String

Returns
int
load()method 
public function load(filename:String, initialLevel:int = -1):void

Starts up the level manager and loads level description data from an xml file. Start is automatically called when this finishes.

Parameters

filename:String — The file to load level descriptions from
 
initialLevel:int (default = -1) — The level to load once everything is set up

loadEntity()method 
public function loadEntity(name:String):IEntity

Loads an entity with the TemplateManager and tracks it. If the current level ends before the entity is destroyed, it will be destroyed automatically.

Parameters

name:String — The name of the entity to instantiate.

Returns
IEntity — The created entity.
loadLevel()method 
public function loadLevel(index:int, force:Boolean = false):void

Loads the specified level and unloads any previous levels. If the previous level and the new level share data, it will not be reloaded.

Parameters

index:int — The level number to load.
 
force:Boolean (default = false) — Force reload.

loadNextLevel()method 
public function loadNextLevel():void

Loads the next level after the current level.

removeFileReference()method 
public function removeFileReference(index:int, filename:String):void

Remove a file from a level number.

Parameters

index:int — The level to remove from
 
filename:String — The file to remove

removeGroupReference()method 
public function removeGroupReference(index:int, name:String):void

Remove a group from a level number.

Parameters

index:int — The level to remove from
 
name:String — The group to remove

removeLevel()method 
public function removeLevel(index:int):void

Removes the level with the specified index.

Parameters

index:int — The index of the level to remove.

serialize()method 
public function serialize(xml:XML):void

serializes the object to XML. This should not include the main tag defining the class itself.

Parameters

xml:XML — The xml object to which the serialization of this class should be added. This xml object is a single tag containing the main class definition, so only children of this class should be added to it.

setLoadFileCallbacks()method 
public function setLoadFileCallbacks(load:Function, unload:Function):void

With this method, you can override the default file loading methods by having custom functions called instead of the defaults.

Parameters

load:Function — The function to call to load files
 
unload:Function — The function to call to unload files

setLoadGroupCallbacks()method 
public function setLoadGroupCallbacks(load:Function, unload:Function):void

With this method, you can override the default group loading methods by having custom functions called instead of the defaults.

Parameters

load:Function — The function to call to load groups
 
unload:Function — The function to call to unload groups

start()method 
public function start(initialLevel:int = -1):void

Starts up the LevelManager. This is automatically called if level descriptions are loaded from a file with the Load method. Otherwise, this should be called after all the level data has been registered with AddFileReference and AddGroupReference. When everything is ready (except for the initialLevel loading), LevelEvent.READY_EVENT is dispatched.

Parameters

initialLevel:int (default = -1) — The level to load once everything is set up

unloadCurrentLevel()method 
public function unloadCurrentLevel():void

Unloads all the currently loaded data. Do not use this when another level is being loaded. Allow the load() method to handle unloading old data.

Event Detail
LEVEL_LOADED_EVENT Event
Event Object Type: com.pblabs.engine.core.LevelEvent
LevelEvent.type property = com.pblabs.engine.core.LevelEvent.LEVEL_LOADED_EVENT

This event is dispatched by the LevelManager when a level's data has been loaded.
LEVEL_UNLOADED_EVENT Event  
Event Object Type: com.pblabs.engine.core.LevelEvent
LevelEvent.type property = com.pblabs.engine.core.LevelEvent.LEVEL_UNLOADED_EVENT

This event is dispatched by the LevelManager when a level's data has been unloaded.
READY_EVENT Event  
Event Object Type: com.pblabs.engine.core.LevelEvent
LevelEvent.type property = com.pblabs.engine.core.LevelEvent.READY_EVENT

This event is dispatched by the LevelManager when it is ready to be used.