View comments | RSS feed

Loading content

A SWF file can load the following types of content:

Subtopics

Loading SWF files and images
Loading sound and videos
Loading SWF files and images using the <img> tag in a text field
Content delivered using RTMP servers

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 object's 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 LoaderContext object. The LoaderContext class includes three properties that let you define the context of how the loaded content can be used:

For details, see Specifying loading context.

An important property of a Loader object is the contentLoaderInfo property, which is a LoaderInfo object. Unlike most other objects, a LoaderInfo object is shared between the loading SWF file and the loaded content, and it is always accessible to both parties. When the loaded content is a SWF file, it can access the LoaderInfo object through the DisplayObject.loaderInfo property. LoaderInfo objects include information such as load progress, the URLs of loader and loadee, the trust relationship between loader and loadee, and other information. For more information, see Monitoring loading progress.

Loading sound and videos

All SWF files, other than those in the local-with-filesystem sandbox, are allowed to load sound and video from network origins, using the Sound.load(), NetConnection.connect(), and NetStream.play() methods.

Only local SWF files can load media from the local file system. Only SWF files in the local-with-filesystem sandbox or the local-trusted sandbox can access data in these loaded files.

There are other restrictions on accessing data from loaded media. For details, see Accessing loaded media as data.

Loading SWF files and images using the <img> tag in a text field

You can load SWF files and bitmaps into a text field by using the <img> tag, as in the following code:

<img src = 'filename.jpg' id = 'instanceName' >

You can access content loaded this way by using the getImageReference() method of the TextField instance, as in the following code:

var loadedObject:DisplayObject = myTextField.getImageReference('instanceName');

Note, however, that SWF files and images loaded in this way are put in the sandbox that corresponds to their origin.

When you load an image file using an <img> tag in a text field, access to the data in the image may be permitted by a cross-domain policy file. You can check for a policy file by adding a checkPolicyFile attribute to the <img> tag, as in the following code:

<img src = 'filename.jpg' checkPolicyFile = 'true' id = 'instanceName' >

When you load a SWF using an <img> tag in a text field, you can permit access to that SWF file's data through a call to the Security.allowDomain() method.

When you use an <img> tag in a text field to load an external file (as opposed to using a Bitmap class embedded within your SWF), a Loader object is automatically created as a child of the TextField object, and the external file is loaded into that Loader just as if you had used a Loader object in ActionScript to load the file. In this case, the getImageReference() method returns the Loader that was automatically created. No security check is needed to access this Loader object because it is in the same security sandbox as the calling code.

However, when you refer to the content property of the Loader object to access the loaded media, security rules apply. If the content is an image, you need to implement a cross-domain policy file, and if the content is a SWF file, you need to have the code in the SWF file call the allowDomain() method.

Content delivered using RTMP servers

Flash Media Server uses the Real-Time Media Protocol (RTMP) to serve data, audio, and video. A SWF file loads this media by using the connect() method of the NetConnection class, passing an RTMP URL as the parameter. Flash Media Server can restrict connections and prevent content from downloading, based on the domain of the requesting file. For details, see the Flash Media Server documentation.

For media loaded from RTMP sources, you cannot use the BitmapData.draw() and SoundMixer.computeSpectrum() methods to extract run-time graphics and sound data.


Flash CS3


Comments


LeBac said on Oct 5, 2007 at 7:02 AM :
Hello,

I have a html text field in which I am loading html text and with it an image which is loaded from the same domain where swf/html file are located.

The problem is linking from the image. <A HREF... tag works when applied to text, but image only shows cursor change, it does not react on click. Also when image and text are together within <A HREF> tag only text is clickable, link from image again doesn't work.

I was wandering if this is connected somehow with security in sense that loaded image can't execute links with javascript or any link on it. Or is this a bug of the flash html text field rendering?

How to overcome this.
Thanks for reply.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/9.0/main/00000353.html