0
votes

In my flash 4.6 Air project, I have several thousands of html files in assets folder which are generated from some other software. Some html files having images.

Now to secure the html files I encrypt all of them. But when I decrypt them to a string and load to via:

html.htmlLoader.loadString(decryptedString.toString());

or

html.htmlText = decryptedString.toString();

The images are not showing and a blank bordered box is showing with ALT text. These html files have javascript() and it is working. The content of ("samople.htm") html file is like:

<P>Some Text</P>
<IMG SRC="../assets/sample/images/image.GIF" ALT="IMAGE.GIF" WIDTH="203"HEIGHT="105">
<P>Some Text</P>

To check the working When I load html by:

html.location = "/assets/sample/sample.htm";

Then it is showing the image. But when I use string by:

html.htmlText = '<p>some text</P><img src="../assets/sample/images/image.GIF" width="203" height="105"><p>some text</p>';

Then it is not showing image. I have tried to change from src="../assets/ . . ." to src="./assets/ . . ." or src="/assets/ . . ." or src="assets/ . . ."

My motto is to secure the html files in assets folder. Currently I can encrypt/decrypt them all but images are not showing.

I'm new in flex and air. Thanks in advance for any help.

EDIT

Here is my full sample code: Flex/ActionScript

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       creationComplete="initiate()">
    <fx:Script>
        <![CDATA[

            public static var stream:FileStream;
            public static var stream2:FileStream;
            public static var file:File;

            public var readFile:ByteArray;

            public function initiate():void
            {
                file = File.applicationDirectory.resolvePath("assets/sample/sample.htm");

                readFile = new ByteArray;
                stream = new FileStream();
                stream.open(file, FileMode.READ);
                stream.readBytes(readFile);
                stream.close();

                html.htmlText = readFile.toString();//Not showing image.
            }
        ]]>
    </fx:Script>
    <mx:HTML id="html" left="10" top="10" width="220" height="250"/>
    <mx:HTML id="html2" left="240" top="10" width="220" height="250"
             location="assets/sample/sample.htm"/><!--Showing Image-->
</s:WindowedApplication>

And HTML:

<HTML>
<HEAD>
<TITLE>title</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function someFunction(someValue)
    {
        //some code;
    }
</SCRIPT>
</HEAD>
<BODY>
<P>This is image</P>
<P><IMG SRC="/assets/sample/images/myimage.gif" ALT="myimage.gif" WIDTH="203" HEIGHT="105"></P>
</BODY>
</HTML>

myimage.gif is located at: assets/sample/images/myimage.gif

3

3 Answers

1
votes

Zeus rightly said htmlText property does not fully support mainly for security reasons in AIR. So when we place html contents through string the container is not in Application Sandbox (default value: false). But if you are sure that the external contents in html string are trusted then you have to set htmlLoader.placeLoadStringContentInApplicationSandbox to true.

0
votes

If you use a http debugger (in firebug/chrome debugger, use the 'net' tab), you can check out from which folder Flash is trying to load the images.

Probably its related to the .swf file location, not to the loaded html file.

-1
votes

HtmlText for the air with <img tags wont work, no matter what. Adobe air will ignore all the <img tags for security purpose.

Work around is > spark textflow component. There are utilities to convert the htmltext into text flow format text and display it in the textflow supported componenents.