Preload content in StageWebView I would like to get some feedback on my AS3 code below. It's for an Adobe Air mobile app to preload a website in a StageWebView container.
That container will be moved on screen later in the app process. My goal is to show the website content to the user as fast as possible.

// OFF SCREEN - PRELOAD
var webView:StageWebView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( -5000, 0, stage.stageWidth, stage.stageHeight);
webView.loadURL("http://www.example.com/foobar.php");

// ONSCREEN
function showWeb(e:Event=null){
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);
}

btn.addEventListener(MouseEvent.CLICK,  showWeb)


Is there something I could do better?
I'm using Adobe Air 3.6 and Flash CS6.

Thank yoo
I don't think there's anything that can be improved to your approach.

Minor improvements do apply;

function showWeb(e:Event=null){
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);
}


could use some indentation,

btn.addEventListener(MouseEvent.CLICK,  showWeb)


contains a double space and is missing a semicolon.

But I don't think it's possible to preload the StageWebView via some function.

What you DO want to take care of is any errors that might be thrown your way.

For that, add a listener: (code from this SO answer)

webView.addEventListener(ErrorEvent.ERROR, onError);
function onError(e:ErrorEvent):void 
{
    trace("Page is not available.");
}