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 AIR native windows<br />

}<br />

package {<br />

import flash.display.Sprite;<br />

import flash.ev<strong>en</strong>ts.Ev<strong>en</strong>t;<br />

import flash.net.URLRequest;<br />

import flash.display.Loader;<br />

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

{<br />

public function LoadedSWF(){<br />

var loader:Loader = new Loader();<br />

loader.load(new URLRequest("visual.swf"));<br />

loader.cont<strong>en</strong>tLoaderInfo.addEv<strong>en</strong>tList<strong>en</strong>er(Ev<strong>en</strong>t.COMPLETE,loadFlash);<br />

}<br />

}<br />

private function loadFlash(ev<strong>en</strong>t:Ev<strong>en</strong>t):void{<br />

addChild(ev<strong>en</strong>t.target.loader);<br />

}<br />

Note: Older SWF files created using ActionScript 1 or 2 share global states such as class definitions, singletons, and global<br />

variables if they are loaded into the same window. If such a SWF file relies on untouched global states to work correctly,<br />

it cannot be loaded more than once into the same window, or loaded into the same window as another SWF file using<br />

overlapping class definitions and variables. This cont<strong>en</strong>t can be loaded into separate windows.<br />

Loading HTML cont<strong>en</strong>t into a NativeWindow<br />

To load HTML cont<strong>en</strong>t into a NativeWindow, you can either add an HTMLLoader object to the window stage and<br />

load the HTML cont<strong>en</strong>t into the HTMLLoader, or create a window that already contains an HTMLLoader object by<br />

using the HTMLLoader.createRootWindow()method. The following example displays HTML cont<strong>en</strong>t within a 300<br />

by 500 pixel display area on the stage of a native window:<br />

//newWindow is a NativeWindow instance<br />

var htmlView:HTMLLoader = new HTMLLoader();<br />

htmlView.width = 300;<br />

htmlView.height = 500;<br />

//set the stage so display objects are added to the top-left and not scaled<br />

newWindow.stage.align = "TL";<br />

newWindow.stage.scaleMode = "noScale";<br />

newWindow.stage.addChild( htmlView );<br />

//urlString is the URL of the HTML page to load<br />

htmlView.load( new URLRequest(urlString) );<br />

To load an HTML page into a Flex application, you can use the Flex HTML compon<strong>en</strong>t.<br />

SWF cont<strong>en</strong>t in an HTML file is not displayed if the window uses transpar<strong>en</strong>cy (that is the transpar<strong>en</strong>t property of<br />

the window is true) unless the wmode parameter of the object or embed tag used to refer<strong>en</strong>ce the SWF file is set to<br />

either opaque or transpar<strong>en</strong>t. Since the default wmode value is window, by default, SWF cont<strong>en</strong>t is not displayed in<br />

a transpar<strong>en</strong>t window. PDF cont<strong>en</strong>t is not displayed in a transpar<strong>en</strong>t window no matter what wmode value is used.<br />

Also, neither SWF nor PDF cont<strong>en</strong>t is displayed if the HTMLLoader control is scaled, rotated, or if the HTMLLoader<br />

alpha property is set to a value other than 1.0.<br />

Last updated 6/6/2012<br />

902

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

Saved successfully!

Ooh no, something went wrong!