In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: 2009-3-14 wonderfl に任意の画像を埋め込む

complete 引数を追加

@author tkinjo
// forked from hikipuro's 2009-3-14 wonderfl に任意の画像を埋め込む
package  
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.events.Event
	
	[SWF( width=475, height=475, frameRate=60, backgroundColor="#ffffff" )]
	
	/**
	 * complete 引数を追加
	 * 
	 * 
	 * @author tkinjo
	 */
	public class Main extends Sprite
	{
		private var imgData:String = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABkAGQDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJm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UAa9FZH9vR/88G/76o/t6P8A54N/31QBuQXVzakm3uJYS3UxuVz+VE93c3W37RcTTbfu+bIWx+dYf9vR/wDPBv8Avqj+3o/+eDf99UAa9FZH9vR/88G/76o/t6P/AJ4N/wB9UAa9FZH9vR/88G/76o/t6P8A54N/31QBr1ka9/qof940f29H/wA8G/76qlqGoLepGqxldpJ5OaAKFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQB//9k=";
		
		/**
		 * 
		 */
		public function Main() 
		{
			Base64ImageLoader.load( imgData, complete );
		}
		
		/**
		 * 
		 * @param	event
		 */
		private function complete( event:Event ):void {
			
			var img:DisplayObject = event.target.content as DisplayObject;
			
			if ( img ) {
				addChild( img );
				img.x = ( stage.stageWidth - img.width ) / 2;
				img.y = ( stage.stageHeight - img.height ) / 2;
			}
		}
	}
	
}

/**
 * Base64化された画像データを表示可能な形式に変換するクラス
 * 
 * 使い方 :
 * 
 * var complete:Function = function( event:Event ):void {
 *         var display:DisplayObject = event.target.content as DisplayObject;
 *         if (display != null)
 *             addChild(display);
 *     };
 * 
 * Base64ImageLoader.load(data, complete);
 * 
 */
class Base64ImageLoader
{
    import flash.display.Loader;
    import flash.events.Event;
    import flash.utils.ByteArray;
    import mx.utils.Base64Decoder;
    
    static public function load( data:String, complete:Function = null ):Loader
    {
        var byteArray:ByteArray;
        var base64Decoder:Base64Decoder;
        var loader:Loader;
        
        base64Decoder = new Base64Decoder();
        base64Decoder.decode(data);
        
        try {
            byteArray = base64Decoder.toByteArray();
            byteArray.position = 0;
        } catch (e:Error) {
            return null;
        }
        
        loader = new Loader();
		
        if( complete != null )
            loader.contentLoaderInfo.addEventListener( Event.COMPLETE, complete );
        
        loader.loadBytes(byteArray);
        
        return loader;
    }
}