ADOBE FLEX 3
Developer Guide
548
Loading content
A SWF file can load the following types of content:
SWF files
Images
Sound
Video
Loading SWF files and images
You use the Loader class to load SWF files and images (JPG, GIF, or PNG files). Any SWF file, other than one in the
local-with-filesystem sandbox, can load SWF files and images from any network domain. Only SWF files in local
sandboxes can load SWF files and images from the local file system. However, files in the local-with-networking
sandbox can only load local SWF files that are in the local-trusted or local-with-networking sandbox. SWF files in
the local-with-networking sandbox load local content other than SWF files (such as images), however they cannot
access data in the loaded content.
When loading a SWF file from a non-trusted source (such as a domain other than that of the Loader objects root
SWF file), you may want to define a mask for the Loader object, to prevent the loaded content (which is a child of
the Loader object) from drawing to portions of the Stage outside of that mask, as in the following code:
import flash.display.*;
import flash.net.URLRequest;
var rect:Shape = new Shape();
rect.graphics.beginFill(0xFFFFFF);
rect.graphics.drawRect(0, 0, 100, 100);
addChild(rect);
var ldr:Loader = new Loader();
ldr.mask = rect;
var url:String = "http://www.unknown.example.com/content.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
addChild(ldr);
When you call the load() method of the Loader object, you can specify a context parameter, which is a Loader-
Context object. The LoaderContext class includes three properties that let you define the context of how the loaded
content can be used:
checkPolicyFile: Use this property only when loading an image file (not a SWF file). Specify this for an image
file from a domain other than that of the file containing the Loader object. If you set this property to
true, the Loader
checks the origin server for a cross-domain policy file (see “Website controls (cross-domain policy files)” on
page 540). If the server grants permission to the Loader domain, ActionScript from SWF files in the Loader domain
can access data in the loaded image. In other words, you can use the
Loader.content property to obtain a reference
to the Bitmap object that represents the loaded image, or the
BitmapData.draw() method to access pixels from the
loaded image.
securityDomain: Use this property only when loading a SWF file (not an image). Specify this for a SWF file
from a domain other than that of the file containing the Loader object. Only two values are currently supported for
the
securityDomain property: null (the default) and SecurityDomain.currentDomain. If you specify
SecurityDomain.currentDomain, this requests that the loaded SWF file be imported to the sandbox of the loading
SWF file, meaning that it operates as though it had been loaded from the loading SWF files own server. This is only
permitted if a cross-domain policy file is found on the loaded SWF files server, allowing access by the loading SWF

Get ADOBE® FLEX® 3: PROGRAMMING ACTIONSCRIPT™ 3.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.