Posted at

Starling Framework使う時のコピペ用ドキュメントクラス

More than 5 years have passed since last update.


starlingTemplate.as

package 

{
import starling.core.Starling;

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.Rectangle;

/**
* starling つかうときのコピペ用ドキュメントクラス
*/

public class StarlingSample extends Sprite
{
private var _starling : Starling;
public function StarlingSample()
{
if(stage) _initialize(null);
else addEventListener(Event.ADDED_TO_STAGE, _initialize);

}

private function _initialize(event : Event) : void
{
removeEventListener(Event.ADDED_TO_STAGE, _initialize);
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

this.mouseEnabled = false;
this.mouseChildren = false;
this.loaderInfo.addEventListener(Event.COMPLETE, loaderInfo_completeHandler);
}

private function loaderInfo_completeHandler(event : Event) : void
{
Starling.handleLostContext = true;
Starling.multitouchEnabled = false;

_starling = new Starling(Main, stage);
_starling.enableErrorChecking = true;
_starling.start();

this.stage.addEventListener(Event.RESIZE, stage_resizeHandler, false, int.MAX_VALUE, true);
this.stage.addEventListener(Event.DEACTIVATE, stage_deactivateHandler, false, 0, true);
}

private function stage_resizeHandler(event : Event) : void
{
_starling.stage.stageWidth = stage.stageWidth;
_starling.stage.stageHeight = stage.stageHeight;

const viewPort : Rectangle = _starling.viewPort;
viewPort.width = stage.stageWidth;
viewPort.height = stage.stageHeight;
try {
_starling.viewPort = viewPort;
}
catch(error : Error) {
}
}

private function stage_deactivateHandler(event : Event) : void
{
_starling.stop();
stage.addEventListener(Event.ACTIVATE, stage_activateHandler, false, 0, true);
}

private function stage_activateHandler(event : Event) : void
{
stage.removeEventListener(Event.ACTIVATE, stage_activateHandler);
_starling.start();
}
}
}