PDA

View Full Version : resize loaded jpg



ryan786
August 10th, 2007, 04:38 AM
hi guys. I'm using a loader to load a jpg. After it's loaded, I want to resize it. Problem is, when I go to resize it, I get a runtime error saying:

SecurityError: Error #2122: Security sandbox violation: LoaderInfo.content: http://address_omitted_here.swf cannot access http://address_omitted_here.jpg. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
at flash.display::LoaderInfo/get content()
at viewer_fla::MainTimeline/initHandler()Here's the code I was using to load it:

function initHandler(e:Event):void {

e.target.loader.x = 0; e.target.loader.y = 0;
if (e.target.content.width > e.target.content.height) {
e.target.content.width = Global.STAGE_WIDTH;
e.target.content.scaleY = e.target.content.scaleX;
e.target.loader.y += (Global.STAGE_HEIGHT - e.target.content.height)/2;
} else if (e.target.content.height >= e.target.content.width) {
e.target.content.height = Global.STAGE_HEIGHT;
e.target.content.scaleX = e.target.content.scaleY;
e.target.loader.x += (Global.STAGE_WIDTH - e.target.content.width)/2;
}
Global.picsLoaded++;
}
for (i=1; i<=Global.NUMPICS; i++)
{
loader = new Loader();
loader.load(new URLRequest(this["p"+i]));
//loader.load(new URLRequest("p"+i+".jpg"));
loader.contentLoaderInfo.addEventListener(Event.IN IT, initHandler);
clip.getChildByName("pic"+i).addChild(loader);
clip.getChildByName("pic"+i).alpha = 0;
}I can load the pictures fine, it's just when I try to resize them with
e.target.content that I get the error. How else can I resize the pictures?

ryan786
August 10th, 2007, 05:39 AM
I came up with a fix, but it's more of a kludge than anything else. I figured I couldn't do any resizing in the Handler, so each time the handler was called, I incremented a counter. Outside, I had an OnEnterFrame continuously tracking whether the counter changed. When it loaded all the pictures, I accessed the loader via this nifty bit: "clip.getChildByName("pic"+i).getChildAt(0).width = 123;"

Ugly, but worked for me. I'm still curious how to get rid of that Sandbox error above, though.

/Ryan

mathew.er
August 10th, 2007, 06:22 AM
Can't you resize the Loader itself? ... it's a visual component after all.

gligy
August 10th, 2007, 07:46 AM
I found some help about this problem - check it out :

Set this flag to true when you are loading an image (JPEG, GIF, or PNG) from outside the calling SWF file's own domain, and you expect to need access to the content of that image from ActionScript. Examples of accessing image content include referencing the Loader.content property to obtain a Bitmap object, and calling the BitmapData.draw() method to obtain a copy of the loaded image's pixels. If you attempt one of these operations without having specified checkPolicyFile at loading time, you may get a SecurityError exception because the needed policy file has not been downloaded yet.

When you call the Loader.load() method with LoaderContext.checkPolicyFile set to true, Flash Player does not begin downloading the specified object in URLRequest.url until it has either successfully downloaded a relevant cross-domain policy file or discovered that no such policy file exists. Flash Player first considers policy files that have already been downloaded, then attempts to download any pending policy files specified in calls to the Security.loadPolicyFile() method, then attempts to download a policy file from the default location that corresponds to URLRequest.url, which is /crossdomain.xml on the same server as URLRequest.url. In all cases, Flash Player requires that the given policy file exist on its server, that it provide access to the object at URLRequest.url by virtue of the policy file's location, and that it permit access by the domain of the calling SWF file by virtue of one or more <allow-access-from> tags.

If you set checkPolicyFile to true, Flash Player waits until policy file completion to begin the main download that you specify in the Loader.load() method. Therefore, as long as the policy file that you need exists, as soon as you have received any ProgressEvent.PROGRESS or Event.COMPLETE events from the contentLoaderInfo property of your Loader object, the policy file download is complete, and you can safely begin performing operations that require the policy file.

If you set checkPolicyFile to true, and no relevant policy file is found, you will not receive any error indication until you attempt an operation that throws a SecurityError exception. However, once the LoaderInfo object dispatches a ProgressEvent.PROGRESS or Event.COMPLETE event, you can test whether a relevant policy file was found by checking the value of the LoaderInfo.childAllowsParent property.

geoken
August 10th, 2007, 08:13 AM
I'm pretty sure your initial code will work if you change that Init event listener to a "Complete" event listener.

_dfm_
November 13th, 2007, 05:18 PM
@ryan786 I have solve this SecurityError: Error #2122, read more at http://theflashblog-bg.com/index.php?p=40