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 />

Security<br />

The StoreAPI object calls the main application to retrieve the regular album price, but returns “Not available” wh<strong>en</strong><br />

the getSaleAlbumPrice() method is called. The following code defines the StoreAPI class:<br />

public class StoreAPI<br />

{<br />

private static var musicStore:Object;<br />

}<br />

public function StoreAPI(musicStore:Object)<br />

{<br />

this.musicStore = musicStore;<br />

}<br />

public function getRegularAlbumPrice():String {<br />

return musicStore.getRegularAlbumPrice();<br />

}<br />

public function getSaleAlbumPrice():String {<br />

return "Not available";<br />

}<br />

public function getAlbumPrice():String {<br />

return musicStore.getRegularAlbumPrice();<br />

}<br />

The following code repres<strong>en</strong>ts an example of a PriceQuoter SWF file that reports the store’s price, but cannot report<br />

the sale price:<br />

package<br />

{<br />

import flash.display.Sprite;<br />

import flash.system.Security;<br />

import flash.text.*;<br />

}<br />

public class PriceQuoter ext<strong>en</strong>ds Sprite<br />

{<br />

private var storeRequester:Object;<br />

}<br />

public function PriceQuoter() {<br />

trace("Initializing child SWF");<br />

trace("Child sandbox: " + Security.sandboxType);<br />

storeRequester = loaderInfo.par<strong>en</strong>tSandboxBridge;<br />

}<br />

var tf:TextField = new TextField();<br />

tf.autoSize = TextFieldAutoSize.LEFT;<br />

addChild(tf);<br />

tf.app<strong>en</strong>dText("Store price of album is: " + storeRequester.getAlbumPrice());<br />

tf.app<strong>en</strong>dText("\n");<br />

tf.app<strong>en</strong>dText("Sale price of album is: " + storeRequester.getSaleAlbumPrice());<br />

Last updated 6/6/2012<br />

1077

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

Saved successfully!

Ooh no, something went wrong!