# [flash] 讀入不同domain圖片

- URL: https://justfly.idv.tw/flash-%e8%ae%80%e5%85%a5%e4%b8%8d%e5%90%8cdomain%e5%9c%96%e7%89%87/
- 日期: 2010-02-24
- 分類: WEB&amp;RIA
- 標籤: actionscript, error, flash, RIA, xml

[這個方法](http://d.hatena.ne.jp/nitoyon/20071112/crossdomain_img)必須要能在目標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);
}
```
