Packagestarling.core
Classpublic class Starling
InheritanceStarling Inheritance EventDispatcher Inheritance Object

The Starling class represents the core of the Starling framework.

The Starling framework makes it possible to create 2D applications and games that make use of the Stage3D architecture introduced in Flash Player 11. It implements a display tree system that is very similar to that of conventional Flash, while leveraging modern GPUs to speed up rendering.

The Starling class represents the link between the conventional Flash display tree and the Starling display tree. To create a Starling-powered application, you have to create an instance of the Starling class:

var starling:Starling = new Starling(Game, stage);

The first parameter has to be a Starling display object class, e.g. a subclass of starling.display.Sprite. In the sample above, the class "Game" is the application root. An instance of "Game" will be created as soon as Starling is initialized. The second parameter is the conventional (Flash) stage object. Per default, Starling will display its contents directly below the stage.

It is recommended to store the Starling instance as a member variable, to make sure that the Garbage Collector does not destroy it. After creating the Starling object, you have to start it up like this:

starling.start();

It will now render the contents of the "Game" class in the frame rate that is set up for the application (as defined in the Flash stage).

Accessing the Starling object

From within your application, you can access the current Starling object anytime through the static method Starling.current. It will return the active Starling instance (most applications will only have one Starling object, anyway).

Viewport

The area the Starling content is rendered into is, per default, the complete size of the stage. You can, however, use the "viewPort" property to change it. This can be useful when you want to render only into a part of the screen, or if the player size changes. For the latter, you can listen to the RESIZE-event dispatched by the Starling stage.

Native overlay

Sometimes you will want to display native Flash content on top of Starling. That's what the nativeOverlay property is for. It returns a Flash Sprite lying directly on top of the Starling content. You can add conventional Flash objects to that overlay.

Beware, though, that conventional Flash content on top of 3D content can lead to performance penalties on some (mobile) platforms. For that reason, always remove all child objects from the overlay when you don't need them any longer. Starling will remove the overlay from the display list when it's empty.

Multitouch

Starling supports multitouch input on devices that provide it. During development, where most of us are working with a conventional mouse and keyboard, Starling can simulate multitouch events with the help of the "Shift" and "Ctrl" (Mac: "Cmd") keys. Activate this feature by enabling the simulateMultitouch property.

Handling a lost render context

On some operating systems and under certain conditions (e.g. returning from system sleep), Starling's stage3D render context may be lost. Starling can recover from a lost context if the class property "handleLostContext" is set to "true". Keep in mind, however, that this comes at the price of increased memory consumption; Starling will cache textures in RAM to be able to restore them when the context is lost.

In case you want to react to a context loss, Starling dispatches an event with the type "Event.CONTEXT3D_CREATE" when the context is restored. You can recreate any invalid resources in a corresponding event listener.



Public Properties
 PropertyDefined By
  antiAliasing : int
The antialiasing level.
Starling
  contentScaleFactor : Number
[read-only] The ratio between viewPort width and stage width.
Starling
  context : Context3D
[read-only] The render context of this instance.
Starling
  current : Starling
[static] [read-only] The currently active Starling instance.
Starling
  enableErrorChecking : Boolean
Indicates if Stage3D render methods will report errors.
Starling
  handleLostContext : Boolean
[static] Indicates if Starling should automatically recover from a lost device context.
Starling
  isStarted : Boolean
[read-only] Indicates if this Starling instance is started.
Starling
  juggler : Juggler
[read-only] The default juggler of this instance.
Starling
  multitouchEnabled : Boolean
[static] Indicates if multitouch input should be supported.
Starling
  nativeOverlay : Sprite
[read-only] A Flash Sprite placed directly on top of the Starling content.
Starling
  nativeStage : Stage
[read-only] The Flash (2D) stage object Starling renders beneath.
Starling
  showStats : Boolean
Indicates if a small statistics box (with FPS and memory usage) is displayed.
Starling
  simulateMultitouch : Boolean
Indicates if multitouch simulation with "Shift" and "Ctrl"/"Cmd"-keys is enabled.
Starling
  stage : Stage
[read-only] The Starling stage object, which is the root of the display tree that is rendered.
Starling
  stage3D : Stage3D
[read-only] The Flash Stage3D object Starling renders into.
Starling
  viewPort : Rectangle
The viewport into which Starling contents will be rendered.
Starling
Public Methods
 MethodDefined By
  
Starling(rootClass:Class, stage:Stage, viewPort:Rectangle = null, stage3D:Stage3D = null, renderMode:String = auto)
Creates a new Starling instance.
Starling
 Inherited
addEventListener(type:String, listener:Function):void
Registers an event listener at a certain object.
EventDispatcher
  
deleteProgram(name:String):void
Deletes the vertex- and fragment-programs of a certain name.
Starling
 Inherited
dispatchEvent(event:Event):void
Dispatches an event to all objects that have registered for events of the same type.
EventDispatcher
  
dispose():void
Disposes Shader programs and render context.
Starling
  
getProgram(name:String):Program3D
Returns the vertex- and fragment-programs registered under a certain name.
Starling
 Inherited
hasEventListener(type:String):Boolean
Returns if there are listeners registered for a certain event type.
EventDispatcher
  
hasProgram(name:String):Boolean
Indicates if a set of vertex- and fragment-programs is registered under a certain name.
Starling
  
Make this Starling instance the current one.
Starling
  
registerProgram(name:String, vertexProgram:ByteArray, fragmentProgram:ByteArray):void
Registers a vertex- and fragment-program under a certain name.
Starling
 Inherited
removeEventListener(type:String, listener:Function):void
Removes an event listener from the object.
EventDispatcher
 Inherited
removeEventListeners(type:String = null):void
Removes all event listeners with a certain type, or all of them if type is null.
EventDispatcher
  
start():void
Starts rendering and dispatching of ENTER_FRAME events.
Starling
  
stop():void
Stops rendering.
Starling
Events
 Event Summary Defined By
  Dispatched when a new render context is created.Starling
  Dispatched when the root class has been created.Starling
Public Constants
 ConstantDefined By
  VERSION : String = 1.1
[static] The version of the Starling framework.
Starling
Property Detail
antiAliasingproperty
antiAliasing:int

The antialiasing level. 0 - no antialasing, 16 - maximum antialiasing.

The default value is 0.


Implementation
    public function get antiAliasing():int
    public function set antiAliasing(value:int):void
contentScaleFactorproperty 
contentScaleFactor:Number  [read-only]

The ratio between viewPort width and stage width. Useful for choosing a different set of textures depending on the display resolution.


Implementation
    public function get contentScaleFactor():Number
contextproperty 
context:Context3D  [read-only]

The render context of this instance.


Implementation
    public function get context():Context3D
currentproperty 
current:Starling  [read-only]

The currently active Starling instance.


Implementation
    public static function get current():Starling
enableErrorCheckingproperty 
enableErrorChecking:Boolean

Indicates if Stage3D render methods will report errors. Activate only when needed, as this has a negative impact on performance.

The default value is false.


Implementation
    public function get enableErrorChecking():Boolean
    public function set enableErrorChecking(value:Boolean):void
handleLostContextproperty 
handleLostContext:Boolean

Indicates if Starling should automatically recover from a lost device context. On some systems, an upcoming screensaver or entering sleep mode may invalidate the render context. This setting indicates if Starling should recover from such incidents. Beware that this has a huge impact on memory consumption!

The default value is false.


Implementation
    public static function get handleLostContext():Boolean
    public static function set handleLostContext(value:Boolean):void
isStartedproperty 
isStarted:Boolean  [read-only]

Indicates if this Starling instance is started.


Implementation
    public function get isStarted():Boolean
jugglerproperty 
juggler:Juggler  [read-only]

The default juggler of this instance. Will be advanced once per frame.


Implementation
    public function get juggler():Juggler
multitouchEnabledproperty 
multitouchEnabled:Boolean

Indicates if multitouch input should be supported.


Implementation
    public static function get multitouchEnabled():Boolean
    public static function set multitouchEnabled(value:Boolean):void
nativeOverlayproperty 
nativeOverlay:Sprite  [read-only]

A Flash Sprite placed directly on top of the Starling content. Use it to display native Flash components.


Implementation
    public function get nativeOverlay():Sprite
nativeStageproperty 
nativeStage:Stage  [read-only]

The Flash (2D) stage object Starling renders beneath.


Implementation
    public function get nativeStage():Stage
showStatsproperty 
showStats:Boolean

Indicates if a small statistics box (with FPS and memory usage) is displayed.


Implementation
    public function get showStats():Boolean
    public function set showStats(value:Boolean):void
simulateMultitouchproperty 
simulateMultitouch:Boolean

Indicates if multitouch simulation with "Shift" and "Ctrl"/"Cmd"-keys is enabled.

The default value is false.


Implementation
    public function get simulateMultitouch():Boolean
    public function set simulateMultitouch(value:Boolean):void
stageproperty 
stage:Stage  [read-only]

The Starling stage object, which is the root of the display tree that is rendered.


Implementation
    public function get stage():Stage
stage3Dproperty 
stage3D:Stage3D  [read-only]

The Flash Stage3D object Starling renders into.


Implementation
    public function get stage3D():Stage3D
viewPortproperty 
viewPort:Rectangle

The viewport into which Starling contents will be rendered.


Implementation
    public function get viewPort():Rectangle
    public function set viewPort(value:Rectangle):void
Constructor Detail
Starling()Constructor
public function Starling(rootClass:Class, stage:Stage, viewPort:Rectangle = null, stage3D:Stage3D = null, renderMode:String = auto)

Creates a new Starling instance.

Parameters
rootClass:Class — A subclass of a Starling display object. It will be created as soon as initialization is finished and will become the first child of the Starling stage.
 
stage:Stage — The Flash (2D) stage.
 
viewPort:Rectangle (default = null) — A rectangle describing the area into which the content will be rendered.
 
stage3D:Stage3D (default = null) — The Stage3D object into which the content will be rendered.
 
renderMode:String (default = auto) — Use this parameter to force "software" rendering.
Method Detail
deleteProgram()method
public function deleteProgram(name:String):void

Deletes the vertex- and fragment-programs of a certain name.

Parameters

name:String

dispose()method 
public function dispose():void

Disposes Shader programs and render context.

getProgram()method 
public function getProgram(name:String):Program3D

Returns the vertex- and fragment-programs registered under a certain name.

Parameters

name:String

Returns
Program3D
hasProgram()method 
public function hasProgram(name:String):Boolean

Indicates if a set of vertex- and fragment-programs is registered under a certain name.

Parameters

name:String

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

Make this Starling instance the current one.

registerProgram()method 
public function registerProgram(name:String, vertexProgram:ByteArray, fragmentProgram:ByteArray):void

Registers a vertex- and fragment-program under a certain name.

Parameters

name:String
 
vertexProgram:ByteArray
 
fragmentProgram:ByteArray

start()method 
public function start():void

Starts rendering and dispatching of ENTER_FRAME events.

stop()method 
public function stop():void

Stops rendering.

Event Detail
context3DCreate Event
Event Object Type: starling.events.Event

Dispatched when a new render context is created.

rootCreated Event  
Event Object Type: starling.events.Event

Dispatched when the root class has been created.

Constant Detail
VERSIONConstant
public static const VERSION:String = 1.1

The version of the Starling framework.