Skip to main content
Participating Frequently
October 10, 2012
Question

Stage Webview on new screen

  • October 10, 2012
  • 1 reply
  • 1418 views

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,onChanging);

    

     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,onChanging);

    

     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();

   

}

This topic has been closed for replies.

1 reply

October 11, 2012

What do you mean by getting it to show on a new Stage?

Participating Frequently
October 11, 2012

I mean new frame Or new page

Known Participant
October 23, 2012

as to be on a new stage , just add it to a diff frame in your porject.

so lets say you init iate the code in frame 3 , then create a button in frame 1 or any other frame so that when you click the button the stage webview will open in the other frame .

what so ever , dont use the code you have now . the code you provided is already scaled to fit elements on stage , you dont want that

use  a simple web view code such as this .

var webView:StageWebView = new StageWebView();

webView.stage = this.stage;

webView.viewPort = new Rectangle(0, 0,0,840 ); /// the numbers in here are to scale

webView.loadURL( "http://ameerw.com" );

[your button].addEventListener(MouseEvent.CLICK, closeWebView);

function closeWebView(e:MouseEvent):void

{

     webView.stage = null;

     webView.dispose();

}

where i  marked numbers to scale make sure you do not scale the webview to fit the whole stage . you need an extra space to

create the bakc button . back button will be used for 2 things . one to remove/dispose the webview then navigate to which ever frame you want it to go to .

i used a function to do this . and you can just create a navigation function etc . for the same button.