Created
June 23, 2014 08:06
-
-
Save shvyrev/b7ca2fd811358afd1514 to your computer and use it in GitHub Desktop.
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
/** | |
* Created by s.shvyrev on 17.06.2014. | |
*/ | |
package utils { | |
import flash.display.Bitmap; | |
import flash.display.Shape; | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.geom.Rectangle; | |
public class PreloaderImage extends Sprite { | |
[Embed(source="/assets/image.png")] | |
private var Image:Class; | |
private var _bmp:Bitmap; | |
private var _gradusnik:Shape; | |
public var color:uint = 0x7dad3e; | |
private var _mask:Bitmap; | |
private var lastTime:Number; | |
public function PreloaderImage() { | |
super(); | |
addEventListener(Event.ADDED_TO_STAGE, added); | |
addEventListener(Event.REMOVED_FROM_STAGE, removed); | |
} | |
private function added(event:Event):void { | |
removeEventListener(Event.ADDED_TO_STAGE, added); | |
_bmp = new Image(); | |
addChild(_bmp); | |
var rect:Rectangle = getBounds(_bmp); | |
_gradusnik = new Shape(); | |
_gradusnik.graphics.beginFill(color); | |
_gradusnik.graphics.drawRect(0, 0, rect.width << 1, rect.height); | |
_gradusnik.graphics.endFill(); | |
addChild(_gradusnik); | |
_gradusnik.cacheAsBitmap = true; | |
_gradusnik.x = -_gradusnik.width; | |
_mask = new Bitmap(_bmp.bitmapData) | |
addChild(_mask); | |
_mask.cacheAsBitmap = true; | |
_gradusnik.mask = _mask; | |
} | |
public function start():void { | |
lastTime = (new Date()).time; | |
addEventListener(Event.ENTER_FRAME, update); | |
} | |
private function update(event:Event):void { | |
_gradusnik.x += ((_gradusnik.width << 1) - _gradusnik.x) * .025; | |
if(_gradusnik.x >= _gradusnik.width) | |
_gradusnik.x = -_gradusnik.width; | |
} | |
public function stop():void { | |
removeEventListener(Event.ENTER_FRAME, update); | |
} | |
public function dispose():void { | |
removeEventListener(Event.ADDED_TO_STAGE, added); | |
removeEventListener(Event.ENTER_FRAME, update); | |
super.removeChildren(); | |
_gradusnik = null; | |
_mask = null; | |
_bmp.bitmapData.dispose(); | |
_bmp = null; | |
removeEventListener(Event.REMOVED_FROM_STAGE, removed); | |
} | |
private function removed(event:Event):void { | |
dispose(); | |
} | |
} | |
} |
donotfeedaslender
commented
Jul 18, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment