package com.skylanders { //import classes you need to make you class work, the imported one are from public available ones. //Importing a class at the package level makes it available throughout your class. import flash.display.*; //- flash's sub classes for display, such as movieclips and it's display properties. import flash.events.*; //- flash's sub classes for user input, event listeners, actions. import flash.display.MovieClip; import flash.geom.Matrix; import flash.geom.Rectangle; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.utils.setTimeout; import com.fbf.events.VariableChangedEvent; /* * author: Alec Moors * support from Ben Whiting */ public class SkylandersSCButtonRight extends MovieClip { //size info protected var _x :Number; protected var _y :Number; protected var _width :Number; protected var _height :Number; protected var _offset :Number; //container for all the created elements public var mc_graphics :MovieClip; private var _buttonReady :Boolean; protected var _bg :Shape; private var _hasbeenBuilt :Boolean = false; private var _onClick :Function; private var btn_txt :DisplayObject; private var _built :Boolean; public function SkylandersSCButtonRight() { stop(); //create and add children _bg = new Shape(); mc_graphics.addChild(_bg); _buttonReady = false; stage ? init() : addEventListener(Event.ADDED_TO_STAGE, init); } public function init(e:Event = null):void { delay = 0; trace("init",e); stage.addEventListener(VariableChangedEvent.CHANGED, build2); addEventListener(Event.ENTER_FRAME, build); } var delay:int; var intervalIdentifier public function build2(e:Event = null):void { delay = 0; addEventListener(Event.ENTER_FRAME, build3); //intervalIdentifier = setTimeout(build4, 3000) } public function build3(e:Event = null) { trace("build3",e,delay); if (++delay < 33) { btn_placeholder.visible = true; btn_placeholder.alpha = 1-(delay/33); return; } else { removeEventListener(Event.ENTER_FRAME, build3); addEventListener(Event.ENTER_FRAME, build); } } public function build4():void { trace('build4') //clearTimeout(intervalIdentifier) addEventListener(Event.ENTER_FRAME, build); } public function build(e:Event = null):void { trace("build",e); if(e) removeEventListener(Event.ENTER_FRAME, build); btn_placeholder.visible = false; _x = -btn_placeholder.width/2; _y = -btn_placeholder.height/2; _width = btn_placeholder.width; _height = btn_placeholder.height; var colours:Array = [0xf79a9a, 0xdb0808, 0xf10b0b, 0xf79a9a]; var ratios:Array = [0x00 * 0, 0xFF * 0.3, 0xFF * 0.35, 0xFF]; var alphas:Array = [1, 1, 1, 1]; var m:Matrix = new Matrix(); m.createGradientBox(_width, _height, Math.PI * 0.5, _x, _y); _bg.graphics.clear(); _bg.graphics.lineStyle(1, 0xe52020, 1, true, LineScaleMode.NORMAL); _bg.graphics.beginGradientFill(GradientType.LINEAR, colours, alphas, ratios, m); //_bg.graphics.drawRect(_x, _y, _width, _height); _offset = _height * 0.25; drawPath(); //visible = true; _built = true; } protected function drawPath():void { _bg.graphics.moveTo(_x, _y); _bg.graphics.lineTo(_x + _width - _offset, _y); _bg.graphics.lineTo(_x + _width + _offset, _y + _height); _bg.graphics.lineTo(_x, _y + _height); _bg.graphics.lineTo(_x, _y); } private function buttonReady():void { //trace("buttonReady"); _buttonReady = true; } //immediate draw - for youtube (and the rest - no discrimination please) ---------------------------------------------- public function immediateDraw():void { //removeEventListener(Event.ENTER_FRAME, animate); alpha = 1; build(); /* _x = -btn_placeholder.width/2; _y = -btn_placeholder.height/2; _width = btn_placeholder.width/2; _height = btn_placeholder.height/2; _stroke1.start = 0; _stroke2.start = 0; _cornerPiece.x = _stroke1.startX; _cornerPiece.y = _stroke1.startY; _cornerPiece2.x = _stroke2.startX; _cornerPiece2.y = _stroke2.startY; btn_placeholder.visible = false; _cornerPiece2.visible = true; _cornerPiece2.alpha = 1; _cornerPiece.visible = false; _bg.alpha = 1; if(btn_txt) btn_txt.alpha = 1; trace("immediateDraw"); drawCornerPiece(_cornerPiece2); if(!_hasbeenBuilt) { trace("immediately draw button"); btn_txt = getChildAt(numChildren - 1); //text always on top yo //drawInsideRect(_bg,0x000000,true,0.8); _cornerPieceColour = _colourKeyline; drawInsideRect(_overlay.graphics,_colourKeyline); drawCornerPiece(_cornerPiece2); with(_bg){ graphics.clear(); graphics.lineStyle(1, _cornerPieceColour, 1, true, "normal", CapsStyle.SQUARE, JointStyle.MITER, 3); graphics.beginFill(0x000000,0.8); graphics.drawRect(_x, _y, _width*2, _height*2); graphics.endFill(); } _bg.alpha = 1; _bg.visible = true; _overlay.alpha = 0; btn_txt.visible = true; this.visible = true; this.alpha = 1; _buttonReady = true; _hasbeenBuilt = true; }*/ } } }