這個方法必須要能在目標domain的跟目錄中放入crossdomain.xml為前提
crossdomain.xml的內容為(全domain):
1 2 3 4 5 | <?xml version="1.0" ?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-access-from domain="*" secure="true" /> </cross-domain-policy> |
或是個別domain:
1 2 3 4 5 | <?xml version="1.0" ?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy> <allow-access-from domain="*.example.com" secure="true" /> </cross-domain-policy> |
在flash中:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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); } |