0 Replies Latest reply on Sep 16, 2011 9:10 AM by akizor88

    StageWebView compiling bug?

    akizor88

      I'm working on a mobile application and i encountered the next problem.

      On Air compiler/debug everything works fine, but on Android(Samsung galaxy S2) doesn't work that fine.

       

      I'm  loading an HTML page with StageWebView. On navigationContent i have a  button wich has the role of going back through StageWebView's history.

      When  the first page is loaded, the button is hidden (button.visible =  false). After the page is changed, the button appears into view  (button.visible = true). When it goes back through StageWebView's  history the button is shown until he gets to the first view. Then, the  button is hidden again.


      This works fine in Air compiler and debug, but on Android it doesn't hide the button when he's getting back to the first view.

      Here are my codes:

       

      MXML application

      <?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:local="*"
                actionBarVisible="true" 
                overlayControls="false" 
                viewDeactivate="iesire_view(event)">
           
           <fx:Script>
                <![CDATA[
                     import com.soenkerohde.mobile.StageWebViewUIComponent;
                     
                     import flash.utils.Timer;
                     
                     import mx.events.EffectEvent;
                     import mx.events.FlexEvent;
                     import mx.preloaders.DownloadProgressBar;
                     import mx.preloaders.Preloader;
                     import mx.preloaders.SparkDownloadProgressBar;
                     
                     import spark.events.ViewNavigatorEvent;
                     
                     
                     
                     public function stageWebView_locationChangeHandler(event:LocationChangeEvent):void
                     {
                          locatie_url.text = event.location;
                          trace("S-a schimbat in: " + event.location);
                          if (event.location == "http://www.google.com")
                          {
                               history_inapoi.visible = false;
                               
                          }
                          else
                          {
                               history_inapoi.visible = true;
                               
                          }
                     }
                     
                     public function iesire_view(event:ViewNavigatorEvent):void
                     {
                          stageWebView.hide();
                     }
                      
                     
                     
                     public function buton_inapoi(event:Event):void
                     {
                          stageWebView.history_inapoi();
                          
                          
                     }
                     
                     
                     
                ]]>
           </fx:Script>
           
           <s:navigationContent>
                <s:Button id="history_inapoi" label="Inapoi" click="buton_inapoi(event)"/>
           </s:navigationContent>
           <s:titleContent>
                <s:Label id="locatie_url" fontSize="6"/>
           </s:titleContent>
           
           
           <mobile:StageWebViewUIComponent xmlns:mobile="com.soenkerohde.mobile.*" 
                                                   id="stageWebView" 
                                                   url="http://www.google.com"
                                                   locationChange="stageWebView_locationChangeHandler(event)"
                                                   />
           
           <s:BorderContainer width="292" height="70" horizontalCenter="0" verticalCenter="0">
           </s:BorderContainer>
           <s:HGroup width="292" height="71" horizontalAlign="center" horizontalCenter="0"
                       verticalAlign="middle" verticalCenter="0">
                <s:BusyIndicator width="60" height="60"/>
                <s:Label text="Se încarcă datele..."/>
           </s:HGroup>
           
      </s:View>
      
      

       

      ActionScript File

      package com.soenkerohde.mobile{
           
           import flash.display.Bitmap;
           import flash.display.BitmapData;
           import flash.display.Sprite;
           import flash.display.Stage;
           import flash.events.ErrorEvent;
           import flash.events.Event;
           import flash.events.LocationChangeEvent;
           import flash.events.MouseEvent;
           import flash.events.TimerEvent;
           import flash.geom.Rectangle;
           import flash.media.StageWebView;
           
           import flashx.textLayout.formats.BackgroundColor;
           
           import mx.core.UIComponent;
           
           import org.osmf.events.TimeEvent;
      
           [Event(name="complete", type="flash.events.Event")]
           [Event(name="locationChanging", type="flash.events.LocationChangeEvent")]
           [Event(name="locationChange", type="flash.events.LocationChangeEvent")]
      
           public class StageWebViewUIComponent extends UIComponent{
      
                public var yOffset:int = 80;
      
                protected var myStage:Stage;
                private var _url:String;
                private var _text:String;
      
                private var _stageWebView:StageWebView;
      
                public function get stageWebView():StageWebView{
                     return _stageWebView;
                }
      
                public function StageWebViewUIComponent(){
                     addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
                }
      
                public function set url(url:String):void{
                     _url = url;
      
                     if(_stageWebView){
                          _stageWebView.loadURL(url);
                     }
                }
      
                public function set text(text:String):void{
                     _text = text;
      
                     if(_stageWebView){
                          _stageWebView.loadString(text);
                     }
                }
      
                public function hide():void{
                     _stageWebView.stage = null;
                }
      
                public function show():void{
                     _stageWebView.stage = myStage;
                }
      
                public function dispose():void{
                     hide();
                     _stageWebView.dispose();
                }
      
                protected function addedToStageHandler(event:Event):void{
                     this.setStyle("backgroundColor",000000);
                     myStage = event.currentTarget.document.stage;
                     removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
      
                     _stageWebView = new StageWebView();
                     _stageWebView.stage = myStage;
                     _stageWebView.viewPort = new Rectangle(0, 70, myStage.width, myStage.fullScreenHeight - 150);
                     _stageWebView.addEventListener(Event.COMPLETE, completeHandler);
                     _stageWebView.addEventListener(ErrorEvent.ERROR, errorHandler);
                     _stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGING, locationChangingHandler);
                     _stageWebView.addEventListener(LocationChangeEvent.LOCATION_CHANGE, locationChangeHandler);
                     if(_url){
                          _stageWebView.loadURL(_url);
                     }else if(_text){
                          _stageWebView.loadString(_text);
                     }
                     // la incarcare, pagina este ascunsa
                     hide();
                     
                }
                
                
                
                protected function completeHandler(event:Event):void
                {
                     dispatchEvent(event.clone());
                     show();
                }
      
                public function locationChangingHandler(event:Event):void
                {
                     dispatchEvent(event.clone());
                }
      
                public function locationChangeHandler(event:Event):void{
                     dispatchEvent(event.clone());
                     
                }
      
                protected function errorHandler(event:Event):void
                {
                     dispatchEvent(event.clone());
                }
                
                
                
                public function history_inapoi():void
                {
                     _stageWebView.historyBack();
                }
                public function history_inainte():void
                {
                     _stageWebView.historyForward();
                     
                }
      
           }
      }