Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to close webview.stage

Explorer ,
Jan 20, 2013 Jan 20, 2013

Im using this code its working but im not able to close the webview stage. How can I close the webview stage, using on button click?

package  {

    import flash.display.MovieClip;

    import flash.media.StageWebView;

    import flash.geom.Rectangle;

    import flash.events.KeyboardEvent;

    import flash.ui.Keyboard;

    import flash.desktop.NativeApplication;

               

    public class mhtml extends MovieClip{

        private var webView:StageWebView = new StageWebView();

                               

        public function mhtml()

        {

            webView.stage = this.stage;

            webView.viewPort = new Rectangle( 50, 50, 700, 400 );

            webView.loadURL( "http://delta-adv.com/roche/form.php" );

                                               

            stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );

        }

                               

        private function onKey( event:KeyboardEvent ):void

        {

            if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled )

            {

                trace("Back.");

                webView.historyBack();

                event.preventDefault();

            }

            if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled )

            {

                trace("Forward.");

                webView.historyForward();

            }

        }

    }

}

TOPICS
ActionScript
5.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 21, 2013 Jan 21, 2013

webView.dispose();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 21, 2013 Jan 21, 2013

webView.stage = null;

webView.viewPort = null;

webView.dispose();

webView = null;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2013 Jul 01, 2013

i try this code but got compiler errors

package  {           

                import flash.display.SimpleButton;

                import flash.events.MouseEvent;

                import flash.media.StageWebView;

                public class webcloss extends SimpleButton {

                                public function webcloss() {

                                                this.addEventListener(MouseEvent.CLICK,clickF);

                                }

                                private function clickF(e:MouseEvent):void{

                                                webView.stage = null;

                                                webView.viewPort = null;

                                                webView.dispose();

                                                webView = null;

                                }

                }

}

1.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jul 01, 2013 Jul 01, 2013

you forgot this line from your original code:

private var webView:StageWebView = new StageWebView();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 01, 2013 Jul 01, 2013

o yes...thx, in this time i got TypeErro

2.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 01, 2013 Jul 01, 2013

Please always paste the code all around the line the error points to (14 in this case).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 02, 2013 Jul 02, 2013

This is the code which I use and I got type error

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at webcloss/clickF()

14 line is in red colour. how can I solve this??

package  {           

                import flash.display.SimpleButton;

                import flash.events.MouseEvent;

    import flash.media.StageWebView;

                public class webcloss extends SimpleButton {

                                private var webView:StageWebView = new StageWebView();

                                public function webcloss() {

                                                this.addEventListener(MouseEvent.CLICK,clickF);

                                }

                                private function clickF(e:MouseEvent):void{

                                                webView.stage = null;

                                                webView.viewPort = null;

                                                webView.dispose();

                                                webView = null;

                                }

                }

}

3.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 08, 2013 Jul 08, 2013

Where is the code that's actually populating the StageWebView? The typical setup at least requires you specify a Rectangle viewPort and specify the stage on which the StageWebView will display. e.g.:

var swv:StageWebView = new StageWebView();

swv.viewPort = new Rectangle(0,0,500,450); // 500px width, 450px height

swv.stage = this.stage; // set stage of StageWebView to document class

swv.loadString('<p>Hello World'); // load any content

Are you explicitly setting the stage property?

Otherwise you may simply be clicking before the StageWebView is fully initialized. Either set a breakpoint at line 14 and verify in the debugger if the var 'webView' is initialized or just trace it and make sure, e.g. trace("webView: " + webView);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 09, 2013 Jul 09, 2013

4.jpg

5.jpg

in this time when I click first time on my webclose button  I got output message

WebVIew: [object StageWebView]

On 2nd time click I got same Type Error

webView: null

TypeError: Error #1009: Cannot access a property or method of a null object reference.

                at webcloss/clickF()

6.jpg

7.jpg

This the code which I use in webcloss button

package  {           

    import flash.display.SimpleButton;

    import flash.events.MouseEvent;

    import flash.media.StageWebView;

                public class webcloss extends SimpleButton {

                                private var webView:StageWebView = new StageWebView();

                                public function webcloss() {

                                                this.addEventListener(MouseEvent.CLICK,clickF);

                                }

                                private function clickF(e:MouseEvent):void{

                                                trace("webView: " + webView);

                                                webView.stage = null;

                                                webView.viewPort = null;

                                                webView.dispose();

                                                webView = null;

                                }

                }

}

and this is LoadForm code

package  {

    import flash.display.SimpleButton;

    import flash.media.StageWebView;

    import flash.geom.Rectangle;

    import flash.events.KeyboardEvent;

    import flash.ui.Keyboard;

    import flash.desktop.NativeApplication;

    import flash.events.MouseEvent;

    public class LoadForm extends SimpleButton{

        private var webView:StageWebView = new StageWebView();

                                public function LoadForm() {

                                                this.addEventListener(MouseEvent.CLICK,clickF);

                                                }

        public function clickF(e:MouseEvent):void

        {

           var swv:StageWebView = new StageWebView();

           swv.viewPort = new Rectangle(50,50,700,400); // 500px width, 450px height

           swv.stage = this.stage; // set stage of StageWebView to document class

            swv.loadURL("http://delta-adv.com/roche/form.php"); // load any content

            stage.addEventListener( KeyboardEvent.KEY_DOWN, onKey );

           }

        private function onKey( event:KeyboardEvent ):void

        {

            if( event.keyCode == Keyboard.BACK && webView.isHistoryBackEnabled )

            {

               trace("Back.");

               webView.historyBack();

               event.preventDefault();

            }

            if( event.keyCode == Keyboard.SEARCH && webView.isHistoryForwardEnabled )

            {

              trace("Forward.");

              webView.historyForward();

            }

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2013 Jul 09, 2013

I'm assuming you have a library element with the class "webcloss" applied to it? Otherwise I don't see where you're using it. In both scenarios I don't see them closing anything but the single instance of StageWebView they're internally instantiating here:

public class webcloss extends SimpleButton

{

          private var webView:StageWebView = new StageWebView();

When clicked, it will null out that local private variable to the "webcloss" class. I don't see you actually loading anything into that StageWebView so unless there's missing code I'm not seeing, it should do nothing, but not error, just once (as it is). After that if you hit the close button you've already nulled out "private var webView" so it doesn't exist anymore and you'll get the error.

So far it seems like a scope issue. I believe you're loading a StageWebView elsewhere, such as mentioned your "LoadForm" button class:

public class LoadForm extends SimpleButton

{

          private var webView:StageWebView = new StageWebView();

In each of those 2 classes you're instantiating a different StageWebView reference. What I believe you want is to centralize the StageWebView so both buttons can access it simply. A quick example (source files) to illustrate me dropping 2 quick squares on the screen for buttons that communicate with a central class in a very simple way. Not ideal with for applications that need to scale but good enough to illustrate 2 separate library elements communicating with a central class:

Example Source (Saved down to Flash CS5.5, minimum needed for AIR 3.7, feel free to downgrade the AIR version if you use less)

Examine how the simple LoadBtn.as and CloseBtn.use the parent class Main.as (set to the document) to access functions that control one StageWebView instance.

I'm just loading Google:

swv.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 11, 2013 Jul 11, 2013

Is there any problem form my side?

Because when I run this file first time I got this message (I have AIR 3.7)

3.jpg

1.jpg

And when I click on close button (1st time nothing happened) 2nd time I got this type error

2.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 11, 2013 Jul 11, 2013

The initial error is just the difference between Flash CS5.5 and later versions, as CS5.5 always calls AIR version 2.6. Don't worry about that.

Aside that the reason the close button is erroring is I don't see any StageWebView on the screen. You first have to open one by hitting the Load button. Then it shouldn't error. I didn't put in sniffing code to see if it doesn't even exist.

The point of it was to show you how the two buttons will load and close a StageWebView endlessly while doing all the work in a central class. In your example the StageWebViews were separate instead causing the errors closing a SWV even if it's open, after you click it once.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 17, 2013 Jul 17, 2013

thx boss. its work

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 17, 2013 Jul 17, 2013

You're welcome and good luck!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 18, 2015 Oct 18, 2015
LATEST

The simple AS6 code for closing a stagewebview is

your button name goes here.addEventListener(MouseEvent.CLICK, fl_CloseWindow);

function fl_CloseWindow(event:Event):void

{

                      webView.dispose();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines