Monday, February 8, 2010

Error #2122: Security sandbox violation: BitmapData.draw:

SecurityError: Error #2122: Security sandbox violation: BitmapData.draw: http://myDomain
/my.swf cannot access http://profile.ak.fbcdn.net/v225/1105/89/t708240324_893.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::BitmapData/draw()
at com::someClass/someFunction()

I received this on a game I am developing for facebook. Problem was here :

var bmd:BitmapData = new BitmapData(w,h);
try {
bmd.draw(someSprite);
}
catch (err:SecurityError) {
//do something
}

someSprite contained a sprite anotherSprite which had an image which was
loaded from facebook. I didn't need anotherSprite , so I did this :

1.
var ind:int = someSprite.getChildIndex(anotherSprite);
someSprite.removeChild(anotherSprite);
try {
bmd.draw(someSprite);
}
someSprite.addChildAt(anotherSprite,ind);

2. Simply doing someSprite.visible = false didn't help.

3. A better way is to do this, while loading the picture :

Security.loadPolicyFile("http://profile.ak.fbcdn.net/crossdomain.xml");
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.applicationDomain = ApplicationDomain.currentDomain;

try {
imageLoader.load(urlReq,context);
} catch (error:Error) {
trace("something");
}

No comments:

Blog Archive