[flash] 讀入不同domain圖片

這個方法必須要能在目標domain的跟目錄中放入crossdomain.xml為前提
crossdomain.xml的內容為(全domain):

 


   

或是個別domain:

 


   


在flash中:

import flash.system.LoaderContext;

// LoaderContext準備
var context:LoaderContext = new LoaderContext(true);

var loader:Loader = new Loader();
var req:URLRequest = new URLRequest("http://www.example.com/sample.gif");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoad_Complete);
loader.load(req, context); // 加入第2個參數
addChild(loader);

private function imageLoad_Complete(e:Event):void {
 var _bit:Bitmap = Bitmap(e.target.content);  
 _pic = new MovieClip();
//為了放大時讓中心點會在中間
 _pic.x = imgWidth / 2; //imgWidth 請自行宣告
 _pic.y = imgHeight / 2; //imgHeight 請自行宣告

 _bit.width = imgWidth;
 _bit.height = imgHeight;
 _bit.x = imgWidth / 2 * -1;
 _bit.y = imgHeight / 2 * -1;
			
 addChild(_pic);
 _pic.addChild(_bit);
}