Skip to main content
Participant
Jan 28, 2011 9:42 PM UTC
Question

StageWebView for Local HTML file

I simply cannot get this to work.  I see a lot of people offering advice on the web for how to implement it, I've been trying all day and it doesn't work with Adobe AIR 2.5 for Android Flash CS5 plug-in.

Instead of linking to an external website:

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

I want to use StageWebView (because of the nice scroll capability) to load a local html file.  I have tried EVERYTHING, and it doesn't work.

I have included the file in the APK (tried as a subdirectory and eventually, to simplify testing, I just included it in the same directory so no complex path).

I have tried what others had recommended:

    webView.loadURL("test.html");

I have tried using the filesystem and resolving the path:

    import flash.filesystem.File; 
    var file:File = File.applicationDirectory.resolvePath("test.html") ;
    webView.loadURL(file.nativePath) ;

I have tried numerous change-ups on the filesystem approach, including:

    var file:File = new File("app:/test.html");

and

    webView.loadURL(file.url);

NONE OF THESE THINGS WORK.  Can anyone help me?  I'd like to have scrollable content, included inside the Android app - like a license html file or others.

If none of this will work, any suggestions on creating simple, scrollable content that looks nice (scroll pane, scroll list, anything?)

This topic is closed to new replies. Start a new post to keep the conversation going.

16 replies

Inspiring
Sep 29, 2014 9:02 AM UTC
Participant
Jul 21, 2011 11:11 AM UTC

I have many times and use all above, none of them works on my real NexusS

use this

var tempsource:File = File.applicationDirectory.resolvePath("html/map2.html");
                 var tempFiles:File = File.applicationStorageDirectory;
                tempsource.copyTo(tempFiles,true);
                resultsPageUrl ="file://" + tempsource.nativePath;

or this

public var resultsPageUrl:String = File.applicationDirectory.resolvePath("html/map2.html").nativePath;

it works on FB Simulator and even work on Real Ipad , but none works on Nexus S

yep it is so hard to creat LBS app using AIR.

Translate
Participating Frequently
Jul 21, 2011 5:48 PM UTC

The following works for me on Android (haven't tried specifically on the Nexus S). In general you should use the url property instead of the nativePath property, especially when the target parameter IS a URL.

var webView:StageWebView = new StageWebView();

webView.stage = this.stage;

webView.viewPort = new Rectangle( 0, 0, this.stage.stageWidth, 60 );

//Copy the html file outside the app directory

var templateFile:File = File.applicationDirectory.resolvePath( "adview.html" );

var workingFile:File = File.createTempFile();

templateFile.copyTo( workingFile, true );

try

{

webView.loadURL( workingFile.url );

}

catch (e:Error)

{

trace( e );

}

Translate
Inspiring
Mar 26, 2011 7:40 PM UTC

Hi,

I have made an extended StageWebView Class that lets you:

It lets you:

* Communicate Actionscript with Javascript.
* Communicate Javascript with Actionscript.
* Load local files and resources in a easy way.
* Extend loadString method with AS3 - JS communication.

By example you can call javascript from as3

// call javascript with callack function
webView.bridge.call('someFunctionToCall', callBackFunction, ...arguments );

// reference local resources in a easy way
<img src="appfile:/image.png">

You can find it at:

http://code.google.com/p/stagewebviewbridge/

I will made some simple tutorials at:

http://www.xperiments.es/blog

Comments are welcome.

Translate
Participant
Feb 24, 2011 11:23 PM UTC

I was able to get this work using this work around from Mike Chambers:

http://www.mikechambers.com/blog/2008/11/06/getting-the-file-uri-of-a-file-in-an-air-apps-install-directory/

webView = new StageWebView();

webView.stage = this.stage;

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


var fPath:String = new File(new File("app:/html/index.htm").nativePath).url;

webView.loadURL( fPath );

A bit of a hack/work around, but it works.

-Thomas

Translate
Participating Frequently
Jan 28, 2011 10:54 PM UTC

The problem is that the StageWebView object cannot load a file with an app: URL.

The two workarounds that I know of are:

  1. Copy the file to a temporary file and load the temporary file with loadURL().
  2. Load the file into string and use the loadString() method.

Note that the two methods have different rules as to whether remote or other local resources can be loaded by the HTML.

(See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/StageWebView.html#loadURL%28%29)

Translate
Inspiring
Feb 22, 2011 9:56 AM UTC

Hi Joe,

can you show code snippet for the 1st solution? With loadString you can't load anything else into that page (i..e stylesheet)

Edit: soon after I've posted this question I have found a solution:)

var resultsPageUrl:String = File.applicationDirectory.resolvePath("output-html/result_html_pattern.html").nativePath;

//and later

webView.loadURL(resultsPageUrl);

Edit2: above was just enough to have it working in adl still no joy

Here is an example of temporary file being loaded, this works, http://forums.adobe.com/message/3443946

var source:File = File.applicationDirectory.resolvePath("output-html");//copy entire folder (with css)
var destination:File = File.applicationStorageDirectory;
source.copyTo(destination, true);//copy to the application storage

//get path to the html page within copied folder
var resultsPageUrl:String = "file://" + destination.resolvePath("result_html_pattern.html").nativePath;

best regards

Translate
Participant
Oct 17, 2011 5:32 PM UTC

Thanks to your code snippet. I was struggling for about 3 days on this issue. Thanks again.

Translate