Reputation: 83
Does anyone have a good link to a very simple example of how to set up a working StageWebView?
It's so simple and well documented for iOS, I can't seem to find anything helpful for developing with Adobe Flash Builder.
I have found this code:
import spark.components.Image;
import spark.events.ViewNavigatorEvent;
public var webView:StageWebView = new StageWebView();
public function init():void
{
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 50, stage.stageWidth, stage.stageHeight );
webView.loadURL("http://www.google.com");
}
protected function logoutHandler(event:MouseEvent):void
{
NativeApplication.nativeApplication.exit();
}
]]>
</fx:Script>
How do I then actually attach this to an element that will appear on the screen?
Upvotes: 1
Views: 1044
Reputation: 15955
Not sure if you're referencing a Flex or pure ActionScript project within Flash Builder; however, something like:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
addedToStage="addedToStageHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected var stageWebView:StageWebView;
protected function addedToStageHandler(event:Event):void
{
stageWebView = new StageWebView();
stageWebView.viewPort = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight);
stageWebView.stage = stage;
stageWebView.loadURL("http://maps.google.com/");
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if (stageWebView)
stageWebView.viewPort = new Rectangle(0, 0, unscaledWidth, unscaledHeight);
}
]]>
</fx:Script>
</s:WindowedApplication>
For pure ActionScript, addedToStage
would be the same implementation but you'd handle resize via your own handler lifecycle such as Event.RESIZE
.
References
Upvotes: 1
Reputation: 512
You can use mx ui component in your class & in this component you can add any stagewebview. use Event.ADDED_TO_STAGE listener, to make sure that stage variable has been prepared. Than you can add into stage variable of mx ui component as using addChild function.
<mx:UIComponent x="0" y="0" width="958" height="567" id="component_UI"/>
component_UI.stage.addChild(Your Stagewebview object)
Upvotes: 0