I’ve been trying to render a webpage using the Adobe Flex / Flash builder StageWebView but it’s not scaling the webpage to fit the phones screen dimension and basically cutting the right side of the webpage off. I’ve tried using
<meta name="viewPort" content="width=device-width; initial-scale=1.0;
maximum-scale=1.0; user-scalable=no;" />
This has not worked. Below is the Flex code I’m currently using.
<?xml version="1.0" encoding="utf-8"?>
<fx:Script>
<![CDATA[
import flash.media.StageWebView;
import flash.net.URLRequest;
import spark.events.ViewNavigatorEvent;
protected var webView:StageWebView = new StageWebView();
protected var openBrowser:Boolean = false;
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
if (StageWebView.isSupported)
{
currentState = "normal";
webView.stage = stage;
webView.viewPort = new Rectangle(0,75,stage.stageWidth,stage.stageHeight);
webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLChange);
webView.loadURL("http://nealdrake.com/mls.html");
addEventListener(ViewNavigatorEvent.REMOVING,onRemove);
}
else {
currentState = "unsupported";
lblSupport.text = "StageWebView feature not supported";
}
}
protected function onURLChange(event:LocationChangeEvent):void
{
trace("URL change");
// Uncomment the following line to load in the default browser instead...
//navigateToURL(new URLRequest(event.location));
}
protected function onRemove(event:ViewNavigatorEvent):void
{
this.webView.dispose();
}
]]>
</fx:Script>
<s:states>
<s:State name="normal"/>
<s:State name="unsupported"/>
</s:states>
<s:Label id="lblSupport" includeIn="unsupported" width="95%" horizontalCenter="0" verticalCenter="0"/>
Any help would greatly be appreciated!
I’m surprised it’s cutting off the right hand side rather than the bottom, since that’s what I’d expect from this:
webView.viewPort = new Rectangle(0,75,stage.stageWidth,stage.stageHeight);You need to count for any X or Y offset in your width and height, like this:
webView.viewPort = new Rectangle(0,75,stage.stageWidth,stage.stageHeight - 75);It might be that your StageWebView is being initialised before your app’s size is correct. Try adding a resize handler (listen for Event.RESIZE events on whatever component your code above is taken from) that sets the viewport again.