Packageimpression.players
Classpublic class CanvasPlayer
InheritanceCanvasPlayer Inheritance RenderingPlayer Inheritance BasePlayer Inheritance flash.events.EventDispatcher

The CanvasPlayer class manages the display of Canvas storyboards. A Canvas storyboard has a main background graphic and any number of overlay display elements (Sprites) -- called CanvasElements -- created at design-time. Each overlay element can have an action associated with it -- the action is typically triggered when the user interacts with the element. It is up to the shell author to determine what user interactions cause the action to be performed.

Note that events explicitly defined in the CanvasElement documentation are raised by both the CanvasElement and the CanvasPlayer. You should avoid adding event listeners for these events to both the CanvasPlayer and the CanvasElement objects; if you do, unexpected results may occur.



Public Properties
 PropertyDefined By
 InheritedalwaysCheckComplete : Boolean
Specifies how the object should handle storyboard completion.
BasePlayer
 InheritednarrationComplete : Boolean
Indicates whether narration has finished playing.
BasePlayer
 InheritedrenderingSurface : Sprite
The object to render content on.
RenderingPlayer
  resolver : AssetResolver
[override] The AssetResolver to use to request external assets.
CanvasPlayer
 Inheritedstoryboard : Storyboard
[override] The storyboard associated with the player.
RenderingPlayer
Public Methods
 MethodDefined By
  
CanvasPlayer(renderingSurface:Sprite = null, resolver:AssetResolver = null)
Creates a new instance of the CanvasPlayer.
CanvasPlayer
 Inherited
Causes the player to examine the completion criteria for the current storyboard.
BasePlayer
  
clearElementStyle(action:String, state:String, style:String):void
Deletes a CanvasElement style property.
CanvasPlayer
 Inherited
clearStyle(style:String):void
Deletes a style property, reverting it back to its default value.
RenderingPlayer
  
deactivateAllExcept(exception:* = null):void
Sets the active property of each CanvasElement except exception to false.
CanvasPlayer
  
Returns the CanvasElement associated with an item.
CanvasPlayer
  
Returns an Array containing the CanvasElement objects on the rendering surface.
CanvasPlayer
  
getElementStyle(action:String, state:String, style:String):Object
Retrieves a CanvasElement style property.
CanvasPlayer
  
[static] Retrieves the default style map for CanvasElement objects.
CanvasPlayer
  
[static] Creates a string describing the state of the storyboard.
CanvasPlayer
 Inherited
getStyle(style:String):Object
Retrieves a style property.
RenderingPlayer
  
[static] Retrieves the default style map for the CanvasPlayer.
CanvasPlayer
 Inherited
redraw():void
Forces a complete redraw of the content.
RenderingPlayer
  
[static] Removes all properties set by the player.
CanvasPlayer
  
setElementStyle(action:String, state:String, style:String, value:Object):void
Sets a CanvasElement style property.
CanvasPlayer
  
setStoryboardState(sb:Storyboard, state:String):void
[static]
CanvasPlayer
 Inherited
setStyle(style:String, value:Object):void
Sets a style property.
RenderingPlayer
Protected Methods
 MethodDefined By
  
[override] Removes any connections between the rendering surface and the player.
CanvasPlayer
  
[override] Removes all content from the surface.
CanvasPlayer
 Inherited
Initializes the storyboard.
BasePlayer
  
[override] Loads the storyboard.
CanvasPlayer
 Inherited
Adds a mask to the rendering surface if the maskRenderingSurface style property value is true.
RenderingPlayer
  
[override] Removes known completion criteria from the CompleteRemaining storyboard persisted property.
CanvasPlayer
 Inherited
Draws the background rectangle onto the rendering surface.
RenderingPlayer
  
[override] Renders the content onto the surface.
CanvasPlayer
  
[override] Performs cleanup actions when a storyboard is unloaded.
CanvasPlayer
Events
 Event Summary Defined By
 InheritedDispatched when the BasePlayer needs to resolve completion criteria beyond those defined for the class.BasePlayer
 InheritedDispatched when a storyboard is marked as complete.BasePlayer
 InheritedDispatched when the player begins to load external assets.RenderingPlayer
 InheritedDispatched when all external assets have finished loading.RenderingPlayer
 InheritedDispatched when some type of input or output failure occurs.RenderingPlayer
  Dispatched when an element's active property is changed to true.CanvasPlayer
  Dispatched when an element is first created.CanvasPlayer
  Dispatched when an element's complete property is changed to true.CanvasPlayer
  Dispatched when an element completes loading of a graphic.CanvasPlayer
  Dispatched when an element begins loading of a graphic.CanvasPlayer
  Dispatched when an element is redrawn.CanvasPlayer
 InheritedDispatched after a storyboard is initialized.BasePlayer
 InheritedDispatched when some type of input or output failure occurs.RenderingPlayer
 InheritedDispatched when storyboard loading is complete.BasePlayer
 InheritedDispatched when a storyboard is loaded, but before any processing occurs.BasePlayer
  Dispatched when an element needs to determine the aggregate status of a location.CanvasPlayer
 InheritedDispatched when some type of input or output failure occurs.RenderingPlayer
 InheritedDispatched before a storyboard is unloaded.BasePlayer
 InheritedDispatched when some type of input or output failure occurs.RenderingPlayer
Styles
 Style Description Defined By
 InheritedType: Boolean
Whether or not the primary asset should be resized when loaded to width x height.
RenderingPlayer
 InheritedType: Number
The background color transparency of the rendering surface.
RenderingPlayer
 InheritedType: uint Format: Color
The background color of the rendering surface.
RenderingPlayer
 InheritedType: Boolean
The value of all assets' cacheAsBitmap property that the player should set once the asset is loaded.
RenderingPlayer
 InheritedType: Object
The default LoaderContext object to use when assets are loaded.
RenderingPlayer
  
enableAllDestinations
Type: Boolean
Specifies which elements should be enabled.

If this style value is false, CanvasElement items with an ActionType property value of CanvasElementActionTypes.JUMP or CanvasElementActionTypes.DISPLAY_RANGE will have their (Sprite's) mouseEnabled property value set to false if the value of the associated ChildElement object's destinationStatus property value is either LocationStatusTypes.NOT_AVAILABLE or LocationStatusTypes.UNKNOWN. If this style value is true, the destinationStatus property value is not examined and no special action is taken.

The default value is false.
CanvasPlayer
 InheritedType: Number Format: Length
The height of the rendering surface, in pixels.
RenderingPlayer
 InheritedType: Boolean
Whether or not the rendering surface should be masked to width x height.
RenderingPlayer
  
multipleActivation
Type: Boolean
Specifies whether or not multiple canvas elements can be active at the same time.

If this style value is false, setting the active property of a CanvasElement to true causes the CanvasPlayer to invoke the deactivateAllExcept method with the newly active item passed as the execption parameter. If this style value is false, no action is taken by the CanvasPlayer.

The default value is false.
CanvasPlayer
 InheritedType: Number Format: Length
The width of the rendering surface, in pixels.
RenderingPlayer
Property Detail
resolverproperty
resolver:AssetResolver[override]

The AssetResolver to use to request external assets. When this value is set to a non-null value, the player registers itself with the resolver as an owner, and all content requested is requested using itself as the owner.

If the player is currently loading content, all load actions in progress will be cancelled when this property is set. When removing the references to an existing resolver, the player will unregister itself as an owner. If the new property value is not null, the player will register itself as an owner.


Implementation
    public function get resolver():AssetResolver
    public function set resolver(value:AssetResolver):void
Constructor Detail
CanvasPlayer()Constructor
public function CanvasPlayer(renderingSurface:Sprite = null, resolver:AssetResolver = null)

Creates a new instance of the CanvasPlayer.

Parameters
renderingSurface:Sprite (default = null) — The object to render content on.
 
resolver:AssetResolver (default = null) — The AssetResolver to use to request external assets.
Method Detail
clearElementStyle()method
public function clearElementStyle(action:String, state:String, style:String):void

Deletes a CanvasElement style property.

If action is null or the empty string (""), the style property referenced is the default style property value to use for all actions. If action is not null or the empty string, the style property referenced is the style property value to use for all CanvasElements with an action property value of action. If state is null or the empty string, the style property referenced is the default style property value to use for all states. If state is not null or the empty string, the style property referenced is the style property value to use for all CanvasElements with a state property value of state.

The style parameter value should be one of the styles defined in the CanvasElement object. Note that, for the purposes of retrieving a specific style, the CanvasElementStates.ACTIVE and CanvasElementStates.ACTIVE state values are identical.

Refer to the documentation on the CanvasElement object's redraw() method for more information on the style lookup rules for a CanvasElement.

Parameters

action:String — The action associated with the style.
 
state:String — The state associated with the style.
 
style:String — The name of the style property.

See also

deactivateAllExcept()method 
public function deactivateAllExcept(exception:* = null):void

Sets the active property of each CanvasElement except exception to false.

Invoking this method may cause the element to be redrawn.

Parameters

exception:* (default = null) — An expression identifying the item to exclude. exception can be one of the following types:
  • ChildElement. The method excludes the CanvasElement whose childElement property is item.
  • DisplayObject. The method excludes the first CanvasElement whose contains() method (as defined by the Sprite object) returns true when exception is passed as a parameter to it.
  • CanvasElement. The method excludes the CanvasElement found by iterating through the elements on the rendering surface and comparing each to exception.

See also

detachSurface()method 
override protected function detachSurface():void

Removes any connections between the rendering surface and the player.

This method is invoked by the player when a storyboard is unloaded, the redraw() method is invoked, or the renderingSurface property is changed. When detaching a rendering surface, the CanvasPlayer performs the following actions:

See also

elementOf()method 
public function elementOf(item:*):CanvasElement

Returns the CanvasElement associated with an item.

If an element cannot be found, or renderingSurface is null, null is returned.

Parameters

item:* — An expression identifying the item to find the CanvasElement for. item can be one of the following types:
  • ChildElement. The method returns the CanvasElement whose childElement property is item.
  • DisplayObject. The method returns the first CanvasElement whose contains() method (as defined by the Sprite object) returns true when item is passed as a parameter to it.
  • CanvasElement. The method returns the CanvasElement found by iterating through the elements on the rendering surface and comparing each to item.

Returns
CanvasElement — The CanvasElement associated with item.
eraseSurface()method 
override protected function eraseSurface():void

Removes all content from the surface.

This method is invoked by the player when a storyboard is unloaded or when the redraw() method is invoked. When erasing a rendering surface, the CanvasPlayer performs the following actions:

See also

getElementArray()method 
public function getElementArray():Array

Returns an Array containing the CanvasElement objects on the rendering surface.

Returns
Array — An Array containing the CanvasElement objects on the rendering surface.
getElementStyle()method 
public function getElementStyle(action:String, state:String, style:String):Object

Retrieves a CanvasElement style property.

If action is null or the empty string (""), the style property referenced is the default style property value to use for all actions. If action is not null or the empty string, the style property referenced is the style property value to use for all CanvasElements with an action property value of action. If state is null or the empty string, the style property referenced is the default style property value to use for all states. If state is not null or the empty string, the style property referenced is the style property value to use for all CanvasElements with a state property value of state.

The style parameter value should be one of the styles defined in the CanvasElement object. Note that, for the purposes of retrieving a specific style, the CanvasElementStates.ACTIVE and CanvasElementStates.ACTIVE state values are identical.

Refer to the documentation on the CanvasElement object's redraw() method for more information on the style lookup rules for a CanvasElement.

Parameters

action:String — The action associated with the style.
 
state:String — The state associated with the style.
 
style:String — The name of the style property.

Returns
Object — Style value.

See also

getElementStyleDefinition()method 
public static function getElementStyleDefinition():Object

Retrieves the default style map for CanvasElement objects.

Returns
Object — Default CanvasElement styles object.

See also

getStoryboardState()method 
public static function getStoryboardState(sb:Storyboard):String

Creates a string describing the state of the storyboard.

This method returns a single character to describe the state of the storyboard. If the storyboard is marked complete, "c" is returned. If the storyboard has been initialized, but is not marked complete, "i" is returned. Otherwise "." is returned.

Note that this string only describes the state that the player is aware of. If the shell stores additional data in the storyboard, it is the shell's responsibility to store the additional data if it is needed.

Parameters

sb:Storyboard — The storyboard to describe the state of.

Returns
String — The state of the storyboard.
getStyleDefinition()method 
public static function getStyleDefinition():Object

Retrieves the default style map for the CanvasPlayer.

Returns
Object — Default styles object.

See also

loadStoryboard()method 
override protected function loadStoryboard():void

Loads the storyboard.

This method is invoked by the storyboard property set method when a non-null storyboard object is loaded after initialization (if needed) occurs.

When loading a storyboard, the CanvasPlayer performs the following actions:

See also

removeCompleteRemainingCriteria()method 
override protected function removeCompleteRemainingCriteria():void

Removes known completion criteria from the CompleteRemaining storyboard persisted property.

This method is invoked by the checkForComplete() method if the value of the storyboard property is not null, and the complete event has not been dispatched since the storyboard was loaded.

In addition to the substrings processed by the BasePlayer, the CanvasPlayer will remove the following substrings from the completeRemaining persisted property:

SubstringMeaning
destinationsComplete;All CanvasElements with an ActionType property value of CanvasElementActionTypes.JUMP or CanvasElementActionTypes.DISPLAY_RANGE have their Complete persisted property set to true.
commandsComplete;All CanvasElements with an ActionType property value of CanvasElementActionTypes.POPUP_TEXT or CanvasElementActionTypes.POPUP_GRAPHIC have their Complete persisted property set to true.
popupsShown;All CanvasElements with an ActionType property value of CanvasElementActionTypes.PLAY_SOUND, CanvasElementActionTypes.HYPERLINK, or CanvasElementActionTypes.COMMAND have their Complete persisted property set to true.

See also

renderContent()method 
override protected function renderContent():void

Renders the content onto the surface.

To render content, the CanvasPlayer performs the following actions:

resetStoryboard()method 
public static function resetStoryboard(sb:Storyboard):void

Removes all properties set by the player.

Note that this method also removes interim completion properties used by the player, but not necessarily set by the player.

Parameters

sb:Storyboard — The storyboard to remove properties from.

This method removes the following properties from a storyboard:

  • Initialized
  • CompleteRemaining
  • Complete
  • NarrationComplete
  • The Complete property of each ChildElement object in the storyboard's Commands ChildElementCollection property, if it exists.

This method removes the following properties from each ChildElement in the storyboard's children collection:

  • Active
  • Complete
  • DestinationStatus

See also

setElementStyle()method 
public function setElementStyle(action:String, state:String, style:String, value:Object):void

Sets a CanvasElement style property.

If action is null or the empty string (""), the style property referenced is the default style property value to use for all actions. If action is not null or the empty string, the style property referenced is the style property value to use for all CanvasElements with an action property value of action. If state is null or the empty string, the style property referenced is the default style property value to use for all states. If state is not null or the empty string, the style property referenced is the style property value to use for all CanvasElements with a state property value of state.

The style parameter value should be one of the styles defined in the CanvasElement object. Note that, for the purposes of retrieving a specific style, the CanvasElementStates.ACTIVE and CanvasElementStates.ACTIVE state values are identical.

Refer to the documentation on the CanvasElement object's redraw() method for more information on the style lookup rules for a CanvasElement.

Parameters

action:String — The action associated with the style.
 
state:String — The state associated with the style.
 
style:String — The name of the style property.
 
value:Object

See also

setStoryboardState()method 
public static function setStoryboardState(sb:Storyboard, state:String):void

Parameters

sb:Storyboard
 
state:String

unloadStoryboard()method 
override protected function unloadStoryboard():void

Performs cleanup actions when a storyboard is unloaded.

This method is invoked by the storyboard property set method when the current value of the property is not null and the unload event has not been cancelled.

When unloading a storyboard, the CanvasPlayer performs the following actions:

See also

Event Detail
elementActive Event
Event Object Type: impression.events.CanvasElementEvent
CanvasElementEvent.type property = impression.events.CanvasElementEvent.ELEMENT_ACTIVE

Dispatched when an element's active property is changed to true.

The CanvasElementEvent.ELEMENT_ACTIVE constant defines the value of the type property of a element active event object. This event has the following properties:
PropertyValue
bubblestrue
cancelabletrue; canceling this event object suppresses redraw of the element.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
canvasElementThe CanvasElement object assigned to the target.
actionThe value of the action property of canvasElement.

See also

elementActive Event  
Event Object Type: impression.events.CanvasElementEvent
CanvasElementEvent.type property = impression.events.CanvasElementEvent.ELEMENT_INITIALIZE

Dispatched when an element is first created.

The CanvasElementEvent.ELEMENT_INITIALIZE constant defines the value of the type property of a element initialized event object. This event has the following properties:
PropertyValue
bubblestrue
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
canvasElementThe CanvasElement object assigned to the target.
actionThe value of the action property of canvasElement.

See also

elementComplete Event  
Event Object Type: impression.events.CanvasElementEvent
CanvasElementEvent.type property = impression.events.CanvasElementEvent.ELEMENT_COMPLETE

Dispatched when an element's complete property is changed to true.

The CanvasElementEvent.ELEMENT_COMPLETE constant defines the value of the type property of a element complete event object. This event has the following properties:
PropertyValue
bubblestrue
cancelabletrue; canceling this event object suppresses redraw of the element.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
canvasElementThe CanvasElement object assigned to the target.
actionThe value of the action property of canvasElement.

See also

elementGraphicLoadComplete Event  
Event Object Type: impression.events.CanvasElementEvent
CanvasElementEvent.type property = impression.events.CanvasElementEvent.ELEMENT_GRAPHIC_LOAD_COMPLETE

Dispatched when an element completes loading of a graphic.

The CanvasElementEvent.ELEMENT_GRAPHIC_LOAD_COMPLETE constant defines the value of the type property of a element graphic load complete event object. This event has the following properties:
PropertyValue
bubblestrue
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
canvasElementThe CanvasElement object assigned to the target.
actionThe value of the action property of canvasElement.
elementGraphicLoadInit Event  
Event Object Type: impression.events.CanvasElementEvent
CanvasElementEvent.type property = impression.events.CanvasElementEvent.ELEMENT_GRAPHIC_LOAD_INIT

Dispatched when an element begins loading of a graphic.

The CanvasElementEvent.ELEMENT_GRAPHIC_LOAD_INIT constant defines the value of the type property of a element graphic load init event object. This event has the following properties:
PropertyValue
bubblestrue
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
canvasElementThe CanvasElement object assigned to the target.
actionThe value of the action property of canvasElement.
elementRedraw Event  
Event Object Type: impression.events.CanvasElementEvent
CanvasElementEvent.type property = impression.events.CanvasElementEvent.ELEMENT_REDRAW

Dispatched when an element is redrawn.

The CanvasElementEvent.ELEMENT_REDRAW constant defines the value of the type property of a element redraw event object. This event has the following properties:
PropertyValue
bubblestrue
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
canvasElementThe CanvasElement object assigned to the target.
actionThe value of the action property of canvasElement.

See also

locationStatusRequest Event  
Event Object Type: impression.events.LocationStatusRequestEvent
LocationStatusRequestEvent.type property = impression.events.LocationStatusRequestEvent.LOCATION_STATUS_REQUEST

Dispatched when an element needs to determine the aggregate status of a location. This event is dispatched if an element's action property value is CanvasElementActionTypes.JUMP or CanvasElementActionTypes.DISPLAY_RANGE, and is dispatched when the element is redrawn.

If the aggregate status is LocationStatusTypes.COMPLETE, the complete property is set to true and the CanvasElementEvent.ELEMENT_COMPLETE event is dispatched.

The LocationStatusRequestEvent.LOCATION_STATUS_REQUEST constant defines the value of the type property of a location status request event object. This event has the following properties:
PropertyValue
bubblesfalse
cancelablefalse; there is no default behavior to cancel.
currentTargetThe object that is actively processing the Event object with an event listener.
targetThe object that raised the event.
sbThe Storyboard object assigned to the target.
locationThe location to determine the status of.
status