Skip to main content
Inspiring
February 27, 2011
Answered

Open StageWebView link in new window

  • February 27, 2011
  • 8 replies
  • 4447 views

I have a StageWebView displaying a webpage containing ads that are coming in from AdMob (due to their current lack of support for AS3 and AIR for Android).

However, when a user clicks on the ad, the linked page opens in that small window, so the content is barely even readable. Is there a way to make the browser open the intended link in a new window, seperate from my app?

Obviously AdMob ads were not intended to work this way, as both the user and the adveriser are getting cheated here (due to AdMob's current lack of support for AS3 and AIR for Android).

Thanks!

This topic has been closed for replies.
Correct answer Joe ... Ward

Yes:

  1. Listen for the location change event
  2. Use navigateToURL( event.URL )
  3. Reset the stageWebView location back to your ad page.

8 replies

Joe ... WardCorrect answer
Participating Frequently
February 28, 2011

Yes:

  1. Listen for the location change event
  2. Use navigateToURL( event.URL )
  3. Reset the stageWebView location back to your ad page.
p-wing47Author
Inspiring
February 28, 2011

Thanks Joe! I've read several posts and walkthroughs trying to explain the 'location change event' concept, but apparently my brain wasn't on the same page. When you put it as simply as you did, it all makes sense now! D'oh!

Participating Frequently
October 15, 2012

I have a question as well.  I'm trying to display a stagewebview when the button is clicked but I want the stage webview to be on a new frame and take up the entire frame.  Here is code I have found but I can't get this to work like I need it to.

I'm trying to get Stagewebview to show on a new stage when a button is clicked.  Right now it just shows on the same stage  becuase code is this.stage.

Also, when it shows up on the new page I want to have back button, forward, and refresh and I want it on the top and not taking alot of space and only on the screen where it's showing the web view.

Please help!!!!!!!!!!

Here is the code:

stop();

import flash.display.StageAlign;

import flash.display.StageScaleMode;

import flash.events.MouseEvent;

import flash.net.URLRequest;

import flash.media.StageWebView;

import flash.geom.Rectangle;

stage.align = StageAlign.TOP_LEFT;

stage.scaleMode = StageScaleMode.NO_SCALE;

var webView:StageWebView;

var swvRect:Rectangle;

var swvHeight:Number;

var uiElemsTop:Number=140;

var swvY:Number=140;

var uiElemsBot:Number=40+20+75+20;

var uiElemsHeight:Number=uiElemsTop+uiElemsBot;

infoBox.text="";

infoBox.visible=false;

mainPanel.visible=false;

webBtnsPanel.visible=false;

mcStart.addEventListener(MouseEvent.CLICK,init);

function init(e:MouseEvent):void {

  

    mcStart.removeEventListener(MouseEvent.CLICK,init);

  

    mcStart.visible=false;

  

    mainPanel.btnExit.addEventListener(MouseEvent.CLICK, exitApp);

  

    mainPanel.btnCloseSwv.addEventListener(MouseEvent.CLICK,closeSwv);

  

    mainPanel.btnOpenSwv.addEventListener(MouseEvent.CLICK, openSwv);

  

    infoBox.text="Click open stage web view to begin";

  

    webBtnsPanel.btnNext.addEventListener(MouseEvent.CLICK, nextPage);

  

    webBtnsPanel.btnPrev.addEventListener(MouseEvent.CLICK, prevPage);

  

    webBtnsPanel.btnReload.addEventListener(MouseEvent.CLICK, reloadPage);

  

    webBtnsPanel.btnStop.addEventListener(MouseEvent.CLICK, stopPage);

  

    swvHeight=stage.stageHeight-uiElemsHeight;

  

    infoBox.x=stage.stageWidth/2-infoBox.width/2;

  

    infoBox.y=stage.stageHeight-40;

  

    mainPanel.x=stage.stageWidth/2-mainPanel.width/2;

  

    webBtnsPanel.x=stage.stageWidth/2-webBtnsPanel.width/2;

  

    webBtnsPanel.y=140+swvHeight+20;

  

    mainPanel.visible=true;

  

    infoBox.visible=true;

}

//When the user taps on Exit button, the app quits.

      

      

function exitApp(event:MouseEvent):void {

  

    NativeApplication.nativeApplication.exit(0);

}

function closeSwv(event:MouseEvent):void {

  

    if(webView==null){

      

        return;

    }

  

     webView.removeEventListener(ErrorEvent.ERROR,onError);

   

     webView.removeEventListener(LocationChangeEvent.LOCATION_CHANGING,onC hanging);

   

     webView.removeEventListener(Event.COMPLETE,onComplete);

  

     webView.viewPort=null;

     webView.dispose();

     webView=null;

  

     webBtnsPanel.visible=false;

  

     infoBox.text="Click open stage web view to begin";

}

function openSwv(event:MouseEvent):void {

  

    if(webView!=null){

      

        return;

    }

  

     webBtnsPanel.visible=true;

   

     infoBox.text="";

  

     webView=new StageWebView();

   

     webView.stage= next.stage;

   

     webView.viewPort=new Rectangle(0,swvY,stage.stageWidth,swvHeight);

    

     webView.addEventListener(ErrorEvent.ERROR,onError);

   

     webView.addEventListener(LocationChangeEvent.LOCATION_CHANGING,onChan ging);

   

     webView.addEventListener(Event.COMPLETE,onComplete);

  

     webView.loadURL("http://www.math.uri.edu/~bkaskosz/webview/index.html");

}

function onError(e:ErrorEvent):void {

  

    infoBox.text="Page is not available. Try reloading.";

  

}

function onChanging(e:LocationChangeEvent):void {

  

    infoBox.text="Loading...";

  

}

function onComplete(e:Event):void {

  

    infoBox.text="";

  

}

function nextPage(e:MouseEvent):void {

  

    if(webView==null){

      

        return;

    }

  

    if(!webView.isHistoryForwardEnabled){

      

        return;

    }

  

    webView.historyForward();

  

}

function prevPage(e:MouseEvent):void {

  

    if(webView==null){

      

        return;

    }

  

    if(!webView.isHistoryBackEnabled){

      

        return;

    }

  

    webView.historyBack();

  

}

function reloadPage(e:MouseEvent):void {

  

    if(webView==null){

      

        return;

    }

  

    webView.reload();

  

}

function stopPage(e:MouseEvent):void {

  

    if(webView==null){

      

        return;

    }

  

    webView.stop();

  

}