Created
July 28, 2015 20:23
-
-
Save joshtynjala/fb66c96b2fcf35f9409c to your computer and use it in GitHub Desktop.
Root class for Feathers CreateJS experimental demo at http://joshblog.net/projects/feathers-createjs/demo/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import createjs.Event; | |
import createjs.Rectangle; | |
import createjs.Stage; | |
import createjs.Ticker; | |
import createjs.Touch; | |
import feathers.controls.ButtonState; | |
import feathers.controls.ScrollPolicy; | |
import feathers.controls.SimpleButton; | |
import feathers.controls.supportClasses.BaseScrollContainer; | |
import feathers.controls.supportClasses.LayoutViewPort; | |
import feathers.skins.BitmapSkin; | |
public class Sandbox | |
{ | |
public static function run():void | |
{ | |
new Sandbox(); | |
} | |
public function Sandbox() | |
{ | |
var canvas:HTMLCanvasElement = document.createElement("canvas") as HTMLCanvasElement; | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
document.body.appendChild(canvas); | |
Ticker.setFPS(60); | |
this._stage = new Stage(canvas); | |
createjs.Touch.enable(this._stage); | |
var vp:LayoutViewPort = new LayoutViewPort(); | |
this._container = new BaseScrollContainer(vp); | |
this._container.scrollXPolicy = ScrollPolicy.OFF; | |
this._container.setSize(canvas.width, canvas.height); | |
this._stage.addChild(this._container); | |
var yPosition:Number = 0; | |
for(var i:int = 0; i < 50; i++) | |
{ | |
var button:SimpleButton = this.createButton(); | |
button.name = "Button " + (i + 1).toString(); | |
button.y = yPosition; | |
yPosition += 80; | |
vp.addChild(button); | |
} | |
this["tickListener"] = this.tickListener.bind(this); | |
Ticker.addEventListener("tick", this.tickListener); | |
this["window_resizeHandler"] = this.window_resizeHandler.bind(this); | |
window.addEventListener("resize", this.window_resizeHandler, false); | |
} | |
private var _stage:Stage; | |
private var _container:BaseScrollContainer; | |
private function createButton():SimpleButton | |
{ | |
var upSkin:BitmapSkin = new BitmapSkin("images/button-up-skin.png"); | |
upSkin.scale9Grid = new Rectangle(5, 5, 50, 50); | |
upSkin.name = "upSkin"; | |
var downSkin:BitmapSkin = new BitmapSkin("images/button-down-skin.png"); | |
downSkin.scale9Grid = new Rectangle(5, 5, 50, 50); | |
downSkin.name = "downSkin"; | |
var button:SimpleButton = new SimpleButton(); | |
button.skin = upSkin; | |
button.setSkinForState(ButtonState.DOWN, downSkin); | |
button.width = 200; | |
return button; | |
} | |
private function tickListener(event:createjs.Event):void | |
{ | |
this._stage.update(); | |
} | |
private function window_resizeHandler(event:Object):void | |
{ | |
this._stage.canvas.width = window.innerWidth; | |
this._stage.canvas.height = window.innerHeight; | |
this._container.setSize(window.innerWidth, window.innerHeight); | |
this._stage.update(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment