StageWebView

0
221

The StageWebView allows for web (HTML and Flash on supported devices) and video content to be loaded into a Flex application. StageWebView will utilize the native browser to load HTML into your application.

Let’s review the code below. First, you will notice there is a private variable named stageWebView declared, of type flash.media.StageWebView. Within application Complete of the application, an event handler function is called, which first checks to see if the device supports StageWebView by reading the static property of the StageWeb View class. If this property returns as true, a new instance of StageWebView and a new Rectangle (sized to fill the remaining screen and set to the viewport property of the stageWebView) are created.

There is a TextInput component with the id of urlAddress, which holds the address that will be shown in the StageWebView and a Button labeled GO.

Clicking on the GO button will call the button1_clickHandler method. Within the but ton1_clickHandler method, the loadURL method is called with the urlAddress.text property passed in. This triggers the StageWebView to load the URL.

The results can be seen within Figure 6-12:

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark”
applicationComplete=
“application1_applicationCompleteHandler(event)”>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
privatevar stageWebView:StageWebView;
privatevar rect:Rectangle;
protectedfunction application1_applicationCompleteHandler
(event:FlexEvent):void
{
if(StageWebView.isSupported==true){
stageWebView = new StagewebView();
stageWebView.viewPort = new Rectangle(5,80,stage.width-10,
stage.height-90);
stageWebView.stage = this.stage;
} else {
urlAddress.text = “StageWebView not supported”;
}
}
protectedfunction button1_clickHandler(event:MouseEvent):void
{
stageWebView.loadURL(urlAddress.text);
}
]]>
</fx:Script>
<fx:Declarations>
<!– Place non-visual elements (e.g., services, value objects) here –>
</fx:Declarations>
<s:TextInput id=”urlAddress” left=”5″ right=”80″ top=”15″
text=”http://www.google.com”/>
<s:Button right=”5″ top=”5″ label=”GO” click=”button1_clickHandler(event)”/>
</s:Application>

StageWebView with the Google homepage loaded