Skip to main content
Participating Frequently
February 2, 2011
Answered

Can we use StageWebView to get image( BLOB ) from SQLite?

  • February 2, 2011
  • 6 replies
  • 9814 views

Hello.

  I create my project with actionscript 3.0 the problem is:

  I store the image using BLOB into SQlite, I success to display the Image on the stage by  Loader class,

   but The point of my project is  to get Image(ฺฺBLOB) from SQlite to show on StageWebView.

   How to find out?

sorry about my english

Thank you


This topic has been closed for replies.
Correct answer

"On Android, the nativePath property of a File object pointing to the application directory is an empty string."

So u need to use File.createTempFile() then save image contents to this file

then use its nativePath property of this instance to loadURL like "file://" + f.nativePath

You can also use your approach of using loadString() . But you still need to create temp file in order to get nativePath of the file on android and src should be set to "file://" + f.nativePath

6 replies

Inspiring
March 26, 2011

I have made an extended StageWebView Class that 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.

tonsmart5Author
Participating Frequently
February 3, 2011

thank you Saumitra Bhave to few queries of mine.

and syed mehadi for your advice.

   I appreciate your help

                 "  Your answer are  work both".

    For 2 day.  I try to get image to Html content on StageWebView and Now you make me understand .

               I can not use loadString() to get Image from local resources to Html content.

                        and

                I can use loadURL() to get Image.

    That work and helpful !!

    Thank you very much.

February 3, 2011

Hi,

Answers to few queries of yours.

1. You can NOT do loadstring in which img src attribute takes file:// urls. In order to do so you need to load the HTML using loadURL which use "file://" based URL

Doc Says "The HTML content cannot load local resources, such as image files."

2. Working Code using the tempFile can be as follows

var f:File = File.applicationDirectory.resolvePath("1.png");
var f2:File = File.createTempDirectory();
f.copyTo(f2.resolvePath("2.png"),true);
var s:StageWebView = new StageWebView();
s.viewPort = new Rectangle(0,0,stage.stageWidth, stage.stageHeight);
s.stage = stage;
s.loadURL(f2.url + File.separator +"2.png");

Known Participant
August 23, 2011

Hi, Saumitra Bhave, do you know how to play local video file?

I mean the file which use UrlLoader to load in byteArray formate, and then save it as ***.mp4.

How to play it use StageWebView?

Thanks for your time!

tonsmart5Author
Participating Frequently
February 3, 2011

Hi. Saumitra Bhave

I try This :

var file:File = File.applicationDirectory.resolvePath("myImage.jpg") ;

var temp:File = File.createTempFile();

file.copyTo(temp, true);

trace(temp.nativePath);

   var myHtmlContent:String = "<img src=' "+temp.nativePath+" ' width='119' height='121' /><P>This is my image</P>";

               myStageWebView.loadString( myHtmlContent, "text/html");

It almost finish  because  it copy to " fla13b.tmp ".but  I want to copy to an original type fla13b.jpg  on the temp file .How to do that .

can you help me a bit to complete this goal.

thank you for your help.

February 3, 2011

It's recommended not to modify application directory contents.

so from where you are getting this image, is it already present in your application directory or you are saving it from somewhere?

one quick solution is to copy the image file to application storage directory and load it in StageWebView control from there.

an example code is:

var imgFile : File = new File("path-of-your-image");

var destFile : File = File.applicationStorageDirectory.resolvePath("image-name");

imgFile.copyTo(destFile, true);

stageWebView.loadURL("file://" + destFile.nativePath);

if this too doesn't work, create a debug swf and monitor the logcat output for any errors during loading.

tonsmart5Author
Participating Frequently
February 2, 2011

Thank you Saumitra Bhave

           I try to find it out with your answers. I save my image  to jpg file " myImage.jpg " on my application directory

           and use this function:

                   myStageWebView.loadURL("myImage.jpg");  and  myStageWebView.loadURL("file://myImage.jpg");

          but  not work  and show me "Error #2044: Unhandled ErrorEvent:. text=Load error."

          My real point want to use loadString() like this;

                              var myHtmlContent:String = "<img src='myImage.jpg' width='119' height='121' /><P>This is my image</P>";

                               myStageWebView.loadString( myHtmlContent, "text/html");

              What did i miss something?

             Can you  guide me to figure out;

Correct answer
February 2, 2011

"On Android, the nativePath property of a File object pointing to the application directory is an empty string."

So u need to use File.createTempFile() then save image contents to this file

then use its nativePath property of this instance to loadURL like "file://" + f.nativePath

You can also use your approach of using loadString() . But you still need to create temp file in order to get nativePath of the file on android and src should be set to "file://" + f.nativePath

February 2, 2011

You can achieve it by saving it in a temp file. And then use file:// scheme to loadURL.