13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Security<br />

Ev<strong>en</strong> if a named domain, such as http://example.com, maps to a specific IP address, such as http://192.0.34.166, the<br />

runtimes set up separate security sandboxes for each.<br />

There are two basic methods that a developer can use to grant a SWF file access to assets from sandboxes other than<br />

that of the SWF file:<br />

The Security.allowDomain() method (see “Author (developer) controls” on page 1043)<br />

The URL policy file (see “Website controls (policy files)” on page 1040)<br />

In the Flash Player and AIR runtime security models, there is a distinction betwe<strong>en</strong> loading cont<strong>en</strong>t and extracting or<br />

accessing data. Cont<strong>en</strong>t is defined as media, including visual media the runtimes can display, audio, video, or a SWF<br />

file or HTML that includes displayed media. Data is defined as something that is accessible only to code. Cont<strong>en</strong>t and<br />

data are loaded in differ<strong>en</strong>t ways.<br />

Loading cont<strong>en</strong>t—You can load cont<strong>en</strong>t using classes such as the Loader, Sound, and NetStream classes; through<br />

MXML tags wh<strong>en</strong> using Flex; or through HTML tags in an AIR application.<br />

Extracting data—You can extract data from loaded media cont<strong>en</strong>t by using Bitmap objects, the<br />

BitmapData.draw() and BitmapData.drawWithQuality() methods, the Sound.id3 property, or the<br />

SoundMixer.computeSpectrum() method. The drawWithQuality method is available in Flash Player 11.3 and<br />

higher; AIR 3.3 and higher.<br />

Accessing data—You can access data directly by loading it from an external file (such as an XML file) using classes<br />

such as the URLStream, URLLoader, FileRefer<strong>en</strong>ce, Socket, and XMLSocket classes. AIR provides additional<br />

classes for loading data, such as FileStream, and XMLHttpRequest.<br />

The Flash Player security model defines differ<strong>en</strong>t rules for loading cont<strong>en</strong>t and accessing data. In g<strong>en</strong>eral, there are<br />

fewer restrictions on loading cont<strong>en</strong>t than on accessing data.<br />

In g<strong>en</strong>eral, cont<strong>en</strong>t (SWF files, bitmaps, mp3 files, and videos) can be loaded from anywhere, but if the cont<strong>en</strong>t is from<br />

a domain other than that of the loading code or cont<strong>en</strong>t, it will be partitioned in a separate security sandbox.<br />

There are a few barriers to loading cont<strong>en</strong>t:<br />

By default, local SWF files (those loaded from a non-network address, such as a user’s hard drive) are classified in<br />

the local-with-filesystem sandbox. These files cannot load cont<strong>en</strong>t from the network. For more information, see<br />

“Local sandboxes” on page 1033.<br />

Real-Time Messaging Protocol (RTMP) servers can limit access to cont<strong>en</strong>t. For more information, see “Cont<strong>en</strong>t<br />

delivered using RTMP servers” on page 1051.<br />

If the loaded media is an image, audio, or video, its data, such as pixel data and sound data, can be accessed by a SWF<br />

file outside its security sandbox only if the domain of that SWF file has be<strong>en</strong> included in a URL policy file at the origin<br />

domain of the media. For details, see “Accessing loaded media as data” on page 1054.<br />

Other forms of loaded data include text or XML files, which are loaded with a URLLoader object. Again in this case,<br />

to access any data from another security sandbox, permission must be granted by means of a URL policy file at the<br />

origin domain. For details, see “Using URLLoader and URLStream” on page 1057.<br />

Note: Policy files are never required in order for code executing in the AIR application sandbox to load remote cont<strong>en</strong>t or<br />

data.<br />

Last updated 6/6/2012<br />

1032

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!