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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Working with sound<br />

Security considerations wh<strong>en</strong> loading and playing<br />

sounds<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

Your application’s ability to access sound data can be limited according to the Flash Player or AIR security model. Each<br />

sound is subject to the restrictions of two differ<strong>en</strong>t security sandboxes, the sandbox for the cont<strong>en</strong>t itself (the “cont<strong>en</strong>t<br />

sandbox”), and the sandbox for the application or object that loads and plays the sound (the “owner sandbox”). For<br />

AIR application cont<strong>en</strong>t in the application security sandbox, all sounds, including those loaded from other domains,<br />

are accessible to cont<strong>en</strong>t in the application security sandbox. However, cont<strong>en</strong>t in other security security sandboxes<br />

observe the same rules as cont<strong>en</strong>t running in Flash Player. For more information about the Flash Player security model<br />

in g<strong>en</strong>eral, and the definition of sandboxes, see “Security” on page 1031.<br />

The cont<strong>en</strong>t sandbox controls whether detailed sound data can be extracted from the sound using the id3 property or<br />

the SoundMixer.computeSpectrum() method. It doesn’t restrict the loading or playing of the sound file itself.<br />

The domain of origin of the sound file defines the security limitations of the cont<strong>en</strong>t sandbox. G<strong>en</strong>erally, if a sound file<br />

is located in the same domain or folder as the SWF file of the application or object that loads it, the application or object<br />

will have full access to that sound file. If the sound comes from a differ<strong>en</strong>t domain than the application does, it can still<br />

be brought within the cont<strong>en</strong>t sandbox by using a policy file.<br />

Your application can pass a SoundLoaderContext object with a checkPolicyFile property as a parameter to the<br />

Sound.load() method. Setting the checkPolicyFile property to true tells Flash Player or AIR to look for a policy<br />

file on the server from which the sound is loaded. If a policy file exists, and it grants access to the domain of the loading<br />

SWF file, the SWF file can load the sound file, access the id3 property of the Sound object, and call the<br />

SoundMixer.computeSpectrum() method for loaded sounds.<br />

The owner sandbox controls local playback of the sounds. The application or object that starts playing a sound defines<br />

the owner sandbox.<br />

The SoundMixer.stopAll() method sil<strong>en</strong>ces the sounds in all SoundChannel objects that are curr<strong>en</strong>tly playing, as<br />

long as they meet the following criteria:<br />

The sounds were started by objects within the same owner sandbox.<br />

The sounds are from a source with a policy file that grants access to the domain of the application or object that<br />

calls the SoundMixer.stopAll() method.<br />

However, in an AIR application, cont<strong>en</strong>t in the application security sandbox (cont<strong>en</strong>t installed with the AIR<br />

application) are not restricted by these security limitations.<br />

To find out if the SoundMixer.stopAll() method will indeed stop all playing sounds, your application can call the<br />

SoundMixer.areSoundsInaccessible() method. If that method returns a value of true, some of the sounds being<br />

played are outside the control of the curr<strong>en</strong>t owner sandbox and will not be stopped by the SoundMixer.stopAll()<br />

method.<br />

The SoundMixer.stopAll() method also stops the playhead from continuing for all sounds that were loaded from<br />

external files. However, sounds that are embedded in FLA files and attached to frames in the timeline using the Flash<br />

Authoring tool might start playing again if the animation moves to a new frame.<br />

Last updated 6/6/2012<br />

454

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

Saved successfully!

Ooh no, something went wrong!