AssetUtil
素材の読込をfrom()でできるようにする
+メソッドチェーン
途中
♥0 |
Line 43 |
Modified 2011-06-03 04:41:53 |
MIT License
archived:2017-03-20 10:54:59
ActionScript3 source code
/**
* Copyright lilliliililiiliililiilil ( http://wonderfl.net/user/lilliliililiiliililiilil )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/ynso
*/
package {
import flash.display.Bitmap;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var bitmapAsset:BitmapAsset = new BitmapAsset()
var bitmap:Bitmap = new Bitmap()
bitmapAsset.target(bitmap).fromBase64(base64)
addChild( bitmap )
}
private const base64:String = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAAZiS0dEAPwA/QD8fZBYlwAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB9kMBAUDMyFBbS8AAAD+SURBVDjLpZIxasMwFIY/pZmaIdQ4JWdwBt0heGzwGUIv0ouUTFq8aRe+wwPVl7DxEaxOAjuObUh+EAiJT++h9ylW8n29hrbrAEiThN/bTQ3vt0sgwDnP0VoDICIAoe06rLUKQM3BQ/A+IkJZllhr1WwHET5l2ej8r67RWlM5B8DbPVgURfi6XDgej2RZNmnx83CgaRredzs+9vufzVL1pWitabuODS9m8kCaJPG3FyMipEkyP0LvffDeh77vRyuexzE/nMI5zxERtNbUdf2wepRr4oExJsR95dxEpMo5hiJt5+AoChDKspxVWa3Aq1GvwCP7jDGhKIrwtBDPwv/cHZQ7f5lMpwAAAABJRU5ErkJggg=="
}
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.events.Event;
import mx.utils.Base64Decoder;
class BitmapAsset
{
public function BitmapAsset(){}
private var _target:Bitmap
private var bitmap:Bitmap
private var loader:Loader
public function target(value:Bitmap=undefined):BitmapAsset{if(value){_target=value}return this}
public function fromBase64(value:String):BitmapAsset{
var decoderBase64:Base64Decoder = new Base64Decoder()
decoderBase64.reset()
decoderBase64.decode(value)
loader = new Loader()
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,_onLoaded)
loader.loadBytes(decoderBase64.toByteArray())
return this
}
public function fromClass(value:Class):BitmapAsset{
return this
}
//public function toBase64():String{
// encoderBase64.encode()
// return encoderBase64.toString()
//}
private function _onLoaded(event:Event):void{
_target.bitmapData = Bitmap(loader.content).bitmapData // replace
loader = null
}
}