forked from: forked from: forked from: flash on 2010-11-19

by 9re forked from forked from: forked from: flash on 2010-11-19 (diff: 13)
複数ロードした画像をまとめてBitmap化したあと、matrixで加工したいのに出来ないです・・。
♥0 | Line 49 | Modified 2010-11-23 22:19:23 | MIT License
play

ActionScript3 source code

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

// forked from aruerula's forked from: forked from: flash on 2010-11-19
// forked from 9re's forked from: flash on 2010-11-19
// forked from aruerula's flash on 2010-11-19
package {
    import flash.system.LoaderContext;
    
    //複数ロードした画像をまとめてBitmap化したあと、matrixで加工したいのに出来ないです・・。
    
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.geom.Matrix;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.system.Security;
    public class Main extends Sprite {
        
        private var count:int = 0;
        private var images:Array;
        
        private const WIDTH:int = 200;
        private const HEIGHT:int = 300;
        private const IMAGE_URL:Array = [
            "http://farm3.static.flickr.com/2730/4338304954_e029ce0dab_b.jpg",
            "http://farm3.static.flickr.com/2730/4338304954_e029ce0dab_b.jpg",
            "http://farm3.static.flickr.com/2730/4338304954_e029ce0dab_b.jpg",

        ];
        
        public function Main() {
            
            images = new Array(IMAGE_URL.length);
            
            //Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
            
            for( var i:int=0; i<IMAGE_URL.length; i++ ){
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,init);
            loader.load(new URLRequest(IMAGE_URL[i]), new LoaderContext(true));
            loader.name = i.toString();
            }
            
        }
      
        private function init(event:Event):void{
            images[event.currentTarget.loader.name] = event.currentTarget.loader;
            
            //if(++count == IMAGE_URL.length ) comp();
            
            var matrix:Matrix = new Matrix();
            
            if(++count == IMAGE_URL.length){
                for (var i:int = 0; i < images.length; i++)
                {
                var bmd:BitmapData = new BitmapData(images[i].width,images[i].height);
                // どうなるのが、正解なのかちょっと分からないので、
                // なんともアドバイス出来ませんが、BitmapData.draw(target)をすると、
                // targetのx座標や、scale, rotationなどは全て無視されて、
                // target.x = 0, target.y = 0, target.scaleX = 1, target.scaleY = 1
                // target.rotatoin = 0の状態で描画されます。なので、
                // 63行目のコードは無効です。
                images[i].x = 465 / images.length * i;
                
                matrix.scale(-1,1);
                matrix.translate(images[i].width,0);
                
                bmd.draw(images[i],matrix);
                
                // ということなので・・・質問にたいしての返答にはなっていないかもしれませんが、
                // 反転されたBitmapを平行移動させて並べるのであれば、
                var bm:Bitmap = new Bitmap(bmd);
                bm.x = 465 / images.length * i;
                bm.alpha = 0.8;
                addChild(bm);
                }    
            }
           
            //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,0);
            
            //var destbd:BitmapData = new BitmapData(bd.width,bd.height);
            //destbd.draw(bd,matrix);
            //addChild(new Bitmap(destbd));
        }
        
        //private function comp():void{

      
        //}

    }
}

Forked