3 Replies Latest reply on Jan 16, 2012 3:25 PM by gkcohen

    StageWebView Help?

    IRV6969

      Can someone help me with this code.  When it runs on the desktop the HTML is blank.  On a device IOS or Android the app crashes.  Any ideas where I'm screwing up (please see the init() function)? 

       

       

      -------------BEGIN CODE-------

      <?xml version="1.0" encoding="utf-8"?>

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                          xmlns:s="library://ns.adobe.com/flex/spark"

                          xmlns:mx="library://ns.adobe.com/flex/mx"

                          title="My Fav Site"

                          creationComplete="init()">

                <fx:Declarations>

                          <!-- Place non-visual elements (e.g., services, value objects) here -->

                </fx:Declarations>

                <fx:Script>

                          <![CDATA[

                                    import spark.components.BusyIndicator;

                                    import spark.events.ViewNavigatorEvent;

       

       

                                    protected var webView:StageWebView = new StageWebView();

       

                                    protected var bi:BusyIndicator;

       

                                    protected function htmlLoaded(event:Event):void

                                    {

       

                                    }

       

                                    public function init():void

                                    {

                                              bi = new BusyIndicator();

                                              webView.addEventListener(flash.events.Event.COMPLETE, htmlLoaded);

                                              this.addElement(bi);

                                              bi.visible=true;

                                              webView.stage = this.stage;

                                              webView.viewPort new Rectangle(0,0, stage.stageWidth, stage.stageHeight);

                                              //webView.loadURL(String(data.link));

                                              webView.loadURL("http://slashdot.org");

                                              addEventListener(ViewNavigatorEvent.REMOVING, onRemove);

                                    }

       

                                    protected function onRemove(event:ViewNavigatorEvent):void

                                    {

                                              this.removeElement(bi);

                                              this.webView.dispose();

       

                                    }

       

                          ]]>

                </fx:Script>

       

                <s:navigationContent>

                          <s:Button label="Back" click="navigator.popView()" />

                </s:navigationContent>

       

                <s:Button label="Load Page In native browser" click="navigateToURL(new URLRequest(String(data)))" />

       

      </s:View>

       

      -------------END CODE----------

        • 1. Re: StageWebView Help?
          IRV6969 Level 1

          I forgot to mention I'm using the 4.5 sdk. 

          • 2. Re: StageWebView Help?
            Nelodroid

            <?xml version="1.0" encoding="utf-8"?>

            <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="
            library://ns.adobe.com/flex/spark" title="HTML Content" viewActivate="view1_viewActivateHandler(event)">

             

                <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(20, 100, 450, 450);

                                webView.addEventListener(LocationChangeEvent.LOCATION_CHANGE,onURLCha nge);  

                                webView.loadURL("http://www.google.com");  

                                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"/>

             

            </s:View>

             

             

            May this code help you

            • 3. Re: StageWebView Help?
              gkcohen

              It might be that you are not removing the StageWebView properly. This is how I do it:

               

              var htmlString:String = "<!DOCTYPE HTML><html><body style=background:#000000><p></p></body></html>";

              webView.loadString(htmlString);

              webView.reload();

              webView.viewPort = null;

              webView.dispose();

              webView = null;

               

              Hope that helps