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

StageWebView for Local HTML file

New Here ,
Jan 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

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?)

TOPICS
Development

Views

28.2K

Translate

Translate

Report

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 28, 2011 Jan 28, 2011

Copy link to clipboard

Copied

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)

Votes

Translate

Translate

Report

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
Participant ,
Feb 22, 2011 Feb 22, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Oct 17, 2011 Oct 17, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Aug 26, 2012 Aug 26, 2012

Copy link to clipboard

Copied

i have the same problem please tell to me what is the final soluation

Votes

Translate

Translate

Report

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
Aug 26, 2012 Aug 26, 2012

Copy link to clipboard

Copied

var initialURL :String;            

        // This copies a single file into a subdir of appStorageDir      

              var source:File = File.applicationDirectory.resolvePath("asset/page.html");            

         // create file(s) in a subdir of appStorageDir to simplify cleanup                  

  var destination:File = File.applicationStorageDirectory.resolvePath("asset/page.html");                     // now do the copy and create a ref to our HTML file that a browser will understand                     source.copyTo(destination, true);       

                initialURL = "file://" + destination.nativePath ;            

        webView.loadURL(initialURL);


Workssssssssssssss

Votes

Translate

Translate

Report

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
Community Beginner ,
Oct 10, 2013 Oct 10, 2013

Copy link to clipboard

Copied

This method seems to no longer works with the current AIR SDK. Any chance you have a workaround that does?

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 11, 2014 Aug 11, 2014

Copy link to clipboard

Copied

Indeed it does not work any more on air 3.9.

My workaround is to minify the html file and save the content in a AS class. Then use "loadString" instead of "loadUrl".

Votes

Translate

Translate

Report

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
Community Beginner ,
Oct 19, 2014 Oct 19, 2014

Copy link to clipboard

Copied

can you share your code routine for this?  Im struggling with the same issue and like how you describe your approach to it, just not 100% sure how to write the code from scratch. thanks!

Votes

Translate

Translate

Report

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
Participant ,
Oct 20, 2014 Oct 20, 2014

Copy link to clipboard

Copied

The code looks like this:

var testFile : File = File.applicationDirectory.resolvePath("test.html");

var testFileCopy : File = File.createTempFile();

testFile.copyTo(testFileCopy, true);

webViewInstance.loadURL(testFileCopy.url);

Votes

Translate

Translate

Report

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
Participant ,
Sep 21, 2015 Sep 21, 2015

Copy link to clipboard

Copied

LATEST

is the above code still the best option for android?

Votes

Translate

Translate

Report

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
New Here ,
Feb 24, 2011 Feb 24, 2011

Copy link to clipboard

Copied

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-di...

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

Votes

Translate

Translate

Report

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 ,
Mar 26, 2011 Mar 26, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
New Here ,
Jul 21, 2011 Jul 21, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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 21, 2011 Jul 21, 2011

Copy link to clipboard

Copied

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 );

}

Votes

Translate

Translate

Report

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
Jul 26, 2011 Jul 26, 2011

Copy link to clipboard

Copied

You can try to use this:

var f:File = File.documentsDirectory.resolvePath(String(data));
this.swv.loadURL(f.url);

data is the direction to file html

swv is the StageWebView object item.

Votes

Translate

Translate

Report

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
Participant ,
Sep 29, 2014 Sep 29, 2014

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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