简体   繁体   English

运行时的Flex mx图像源路径

[英]Flex mx Image source path at runtime

I'm wading through a Flex AIR desktop project that someone else wrote. 我正在研究其他人编写的Flex AIR桌面项目。 The original author has used several mx.controls.Image components. 原始作者使用了几个mx.controls.Image组件。 Runtime image paths assigned like this: 这样分配的运行时映像路径:

image.source = "/assets/book.png";

It doesn't work - I just get the broken image icon. 它不起作用-我只得到了残破的图像图标。

I've never used the above approach in my own code. 我从未在自己的代码中使用上述方法。 Personally, I've always used compile-time embedded images or URLLoader/Loader for runtime images. 就个人而言,我一直使用编译时嵌入式图像或URLLoader / Loader作为运行时图像。

So, I'd like to learn how to get this image path approach working. 因此,我想学习如何使这种图像路径方法起作用。

I wrote a simple test program. 我写了一个简单的测试程序。 Here is my .mxml - 这是我的.mxml-

<?xml version="1.0" encoding="utf-8"?>
 <pf:LearningAS xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      xmlns:pf="com.powerflasher.*">
      <mx:Image id="myImage"/>
 </pf:LearningAS>

Here is my connected .as 这是我连接的.as

public class LearningAS extends WindowedApplication {

    public var myImage:Image;

    public function LearningAS() {
        super();
        addEventListener(FlexEvent.CREATION_COMPLETE, init);
    }

    protected function init(event:FlexEvent):void {
        myImage.source = '/assets/myimage.png';
    }
}

I also added the src/assets folder to AIR package contents. 我还将src / assets文件夹添加到AIR包内容中。 And I added -use-network=false to my compiler directives. 我在编译器指令中添加了-use-network = false。 (I'm using FDT, and Flex 4.6). (我正在使用FDT和Flex 4.6)。

Ok - Cracked it, with some help from the Flex mailing list. 好的-在Flex邮件列表的帮助下,将其破解。

I had to copy my assets folder into my bin folder. 我必须将资产文件夹复制到我的bin文件夹中。 So that the paths were relative to the .swf. 这样路径就相对于.swf。 (Actually, I've done this for previous AS3 projects - but I assumed that packaging assets folder for AIR would cover this.) (实际上,我已经为以前的AS3项目完成了此操作-但我认为AIR的打包资产文件夹将涵盖此内容。)

Anyway - problem solved. 无论如何-问题解决了。

As per your code you are giving incorrect image path reference instead of myImage.source = '/assets/myimage.png'; 根据您的代码,您提供了不正确的图像路径引用,而不是myImage.source = '/assets/myimage.png'; / myImage.source = '/assets/myimage.png'; try myImage.source = 'assets/myimage.png'; 试试myImage.source = 'assets/myimage.png';

Hope it work for you. 希望它为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM