【问题标题】:<img> not working in actionscript<img> 在动作脚本中不起作用
【发布时间】:2013-10-16 07:30:08
【问题描述】:

在我的 flash 4.6 Air 项目中,我在 assets 文件夹中有数千个 html 文件,这些文件是由其他一些软件生成的。一些带有图像的 html 文件。

现在为了保护 html 文件,我对它们进行了加密。但是当我将它们解密为字符串并加载到 via 时:

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

html.htmlText = decryptedString.toString();

图像未显示,并且显示带有 ALT 文本的空白边框框。这些 html 文件有 javascript() 并且它正在工作。 ("samople.htm") html 文件的内容是这样的:

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

当我加载 html 时检查工作:

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

然后它显示图像。但是当我使用字符串时:

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

然后它没有显示图像。我试图改变 src="../assets/ . . ."到 src="./assets/ . . ."或 src="/assets/ ..."或 src="assets/..."

我的座右铭是保护资产文件夹中的 html 文件。目前我可以加密/解密它们,但图像没有显示。

我是 flex 和 air 的新手。提前感谢您的帮助。

编辑

这是我的完整示例代码: 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>

还有 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 位于:assets/sample/images/myimage.gif

【问题讨论】:

    标签: html actionscript-3 apache-flex air flex4.5


    【解决方案1】:

    Zeus 正确地说 htmlText 属性不完全支持主要是出于安全原因在 AIR 中。因此,当我们通过字符串放置 html 内容时,容器不在应用程序沙箱中(默认值:false)。但是如果您确定 html 字符串中的外部内容是可信的,那么您必须将 htmlLoader.placeLoadStringContentInApplicationSandbox 设置为 true。

    【讨论】:

      【解决方案2】:

      如果您使用 http 调试器(在 firebug/chrome 调试器中,使用“net”选项卡),您可以查看 Flash 尝试从哪个文件夹加载图像。

      可能与 .swf 文件位置有关,与加载的 html 文件无关。

      【讨论】:

      • 我正在使用带有 AIR 的 Flash Builder 4.6,这是一个 Windows 应用程序。重要的是当我使用 html.location 时它正在工作,但是当我将 html 文件的内容转换为字符串时,它没有显示图像,只有其他所有图像都在工作,甚至是 javascript。
      • 不过,如果您认为图像的路径错误,您应该可以使用 http 调试器进行调试。即使在 AIR 应用程序中,也可以尝试“Charles HTTP 调试器”。
      • 图片路径正确。购买一个新软件并使用它会比较麻烦。我重复 html.htmlText 不工作,但 html.location 工作。
      【解决方案3】:

      带有 出于安全目的,Adobe air 将忽略所有

      解决方法是 > spark textflow 组件。有一些实用程序可以将 htmltext 转换为文本流格式文本并在文本流支持的组件中显示。

      【讨论】:

      • 感谢 Mark 和 Zeus 的回复,但我的问题还没有解决。我在这些 html 文件中有 javascript 并且有 AS JS 调用。现在,我必须将所有图像的解密文件临时保存在用户硬盘上,然后使用正在工作的“.location”属性。
      • 有没有其他方法可以在 AIR 中使用多个带有图像和 javascript 的 html 文件。提前致谢。
      • text.htmlText 属性不完全支持 html 标签,如果你必须显示 html 文件,那么你必须使用 help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/… 可能对您有所帮助。
      • 我可以给的一个建议是,使用Native applciation来做加解密,让air只显示html,native application会在air app请求的时候返回解密后的html文件使用 htmlloader。
      • 非常感谢宙斯再次将我纳入解决方案。我已经使用了 htmlLoader 类(请参阅我的问题中的第一个代码)。我再次彻底阅读了 htmlLoader 类,并在 html.htmlLoader.loadString(fileToEncrypt.toString()); 及其工作!!!。
      猜你喜欢
      • 2022-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 2018-02-26
      相关资源
      最近更新 更多