Created
September 6, 2012 00:22
-
-
Save mechamogera/3648563 to your computer and use it in GitHub Desktop.
action script3でのcrossdomain画像読み込み
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
クロスドメインの画像を読み込む場合、下記のコメントアウトを外して対処しないとcrossdomain.xmlが配置してあっても以下のエラーとなる | |
SecurityError: Error #2122: セキュリティサンドボックス侵害 : BitmapData.draw:file:///hoge/LoadImage.swf は https://example.com/hoge.jpg にアクセスできません。ポリシーファイルが必要ですが、このメディアがロードされたとき、checkPolicyFile フラグが設定されませんでした。 | |
at flash.display::BitmapData/draw() | |
at MethodInfo-1() | |
*/ | |
package { | |
import flash.display.*; | |
import flash.text.*; | |
import flash.net.URLRequest; | |
import flash.system.Security; | |
import flash.system.LoaderContext; | |
import flash.events.Event; | |
public class LoadImage extends Sprite { | |
public function LoadImage () { | |
// Security.loadPolicyFile("https://example.com/crossdomain.xml"); // 明示的にポリシーファイル読み込み | |
var loader:Loader = new Loader(); | |
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadDone); | |
loader.load(new URLRequest("https://example.com/hoge.jpg")); | |
// loader.load(new URLRequest("https://example.com/hoge.jpg"), new LoaderContext(true)); // クロスドメインのポリシーファイル読み込むように設定(デフォルトオフ) | |
function loadDone(event:Event):void { | |
var bd:BitmapData = new BitmapData(loader.width, loader.height); | |
bd.draw(loader); | |
addChild(new Bitmap(bd)); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head></head> | |
<body> | |
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" WIDTH=600 HEIGHT=600> | |
<EMBED SRC="LoadImage.swf" WIDTH=600 HEIGHT=600 bgcolor=#FFFFFF LOOP=false QUALITY=high PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" TYPE="application/x-shockwave-flash" /> | |
</OBJECT> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment