flash on 2010-11-15

by aruerula
http://www40.atwiki.jp/spellbound/pages/63.html
hanten
♥0 | Line 37 | Modified 2010-11-16 00:46:28 | MIT License
play

ActionScript3 source code

/**
 * Copyright aruerula ( http://wonderfl.net/user/aruerula )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4pZU
 */

package
{
    //http://www40.atwiki.jp/spellbound/pages/63.html
    //hanten
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.geom.Matrix;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
 
    public class Main extends Sprite
    {
        private const WIDTH:int = 200; // 幅
        private const HEIGHT:int = 200; // 高さ
 
        public function Main()
        {
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
            loader.load(new URLRequest("http://a1.twimg.com/profile_images/1167468105/ProfilePhoto.png"), new LoaderContext(true)); // 読み込みたい画像URL
        }
 
        private function initHandler(event:Event):void
        {
            var loader:Loader = event.currentTarget.loader;
 
            var matrix:Matrix = new Matrix();
            matrix.scale(WIDTH / loader.width, HEIGHT / loader.height); // 設定したいサイズ / 元サイズ
 
            var bd:BitmapData = new BitmapData(WIDTH, HEIGHT); // 設定したいサイズ
            bd.draw(loader, matrix);
 
            matrix = new Matrix();
            matrix.scale(-1, -1);
            matrix.translate(bd.width, bd.height);
 
            var destbd:BitmapData = new BitmapData(bd.width, bd.height);
            destbd.draw(bd, matrix);
            addChild(new Bitmap(destbd));
        }
    }
}