Error loading local html on StageWebViewBridge

927 Views Asked by At

I´m getting this error when I try to load a local html on StageWebViewBridge container:

Error #2044: Unhandled ErrorEvent:. text=Load error.

code:

private function onDiskCacheEnd( e:StageWebviewDiskEvent ):void{
    bridge = new StageWebViewBridge( 0, 0, 1280, 720 );
    bridge.loadLocalURL('applink://index.html');
...

index.html is located in www folder.

Thanks!

2

There are 2 best solutions below

0
On

Here StageWebView cannot refer the URL you given in loadURL(), because applink is get reference by single slash in the document. But i couldnt try with applink. StageWebViewBridge is doesn't handle ErrorEvent in their override protected addEventListener function. If you need to handle this error event you should add

    override public function addEventListener( type : String, listener : Function, useCapture : Boolean = false, priority : int = 0, useWeakReference : Boolean = false ) : void
    {
        switch( type )
        {
            case ErrorEvent.ERROR:
            case Event.COMPLETE:
            case LocationChangeEvent.LOCATION_CHANGING:
            case LocationChangeEvent.LOCATION_CHANGE:
            case FocusEvent.FOCUS_IN:
            case FocusEvent.FOCUS_OUT:
                _view.addEventListener( type, listener, useCapture, priority, useWeakReference );
                break;
            default:
                super.addEventListener( type, listener, useCapture, priority, useWeakReference );
                break;
        }
    }

and also need to remove listeners like,

  override public function removeEventListener( type : String, listener : Function, useCapture : Boolean = false ) : void
    {
        switch( type )
        {
            case ErrorEvent.ERROR:
            case Event.COMPLETE:
            case LocationChangeEvent.LOCATION_CHANGING:
            case LocationChangeEvent.LOCATION_CHANGE:
            case FocusEvent.FOCUS_IN:
            case FocusEvent.FOCUS_OUT:
                _view.removeEventListener( type, listener, useCapture );
                break;
            default:
                super.removeEventListener( type, listener, useCapture );
                break;
        }
    }

now you can handle the ErrorEvent by

     webView.addEventListener( ErrorEvent.ERROR, onLoadURLErrorTriggered );

and, you always better to give file url to load local html file like,

     var file : File = new File("file-path");
     webView.loadURL( file.url );
0
On

Never actually tried this, but the documentation (https://code.google.com/p/stagewebviewbridge/wiki/ContentLoading) only uses a single slash.

So instead of: 'applink://index.html'

the docs use: "applink:/index.html"