无法获得我的相对路径以使用FlashDevelop和Flex [英] Can't get my relative paths to work with flashDevelop and flex
问题描述
所以我正在使用FlashDevelop和flex,但是我无法使源正常工作.每当我嵌入图像时,它都可以正常工作,但是如果我只是去source ="../img/Koala.jpg",那么我用于工作嵌入的路径将不起作用.在Flash Builder中,我要做的只是source ="/img/Koala.jpg",它的工作原理还不错.如果我输入路径"D:\ flashDevelop \ FlexMobileProject \ src \ img \ Koala.jpg",则可以正常运行.谁能解释一下我在这里想念的吗?
So i am using FlashDevelop and flex but i can't get the source to work correctly. When ever i Embed a image it works just fine but if i just go source="../img/Koala.jpg" same path that i used for the working embed it doesn't work. In flash builder all i would have to do is source="/img/Koala.jpg" and it work work just fine. If i type in the path "D:\flashDevelop\FlexMobileProject\src\img\Koala.jpg" this works fine. Can anyone please explain what i'm missing here?
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="HomeView" creationComplete="init()">
<fx:Script>
<![CDATA[
[Embed(source = "../img/Koala.jpg")]
[Bindable] public var img:Class;
public function init():void {
var s:String = new String();
label.text = String(imgstage.sourceHeight);
trace(imgstage.source);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<!-- can't find the image even if that path is the same as the embed -->
<s:Image id="imgstage" source="../img/Koala.jpg" y="0" x="0"/>
<s:Label id="label" text="name"></s:Label>
</s:View>
推荐答案
为Image指定'source'时,文件将在运行时加载.但是,FlashDevelop不会将文件从src/复制到bin/-您必须使用要在运行时加载的元素手动填充bin/目录.运行时的路径相对于HTML页面是解析的.
When you specify 'source' for an Image, the file will be loaded at run time. However, FlashDevelop doesn't copy the files from src/ to bin/ - you must populate the bin/ directory manually with the elements you want to load at run time. Paths at run time are resolved relatively to the HTML page.
嵌入在编译时已解析,应该注意的是,在使用FlashDevelop时,路径始终是相对于class/mxml文件而不是相对于项目根目录来解析的.如果路径以"/"开头,则它将相对于类路径的根.
Embeds are resolved at compile time, and it should be noted that when using FlashDevelop the path is always resolved relatively to the class/mxml file and not relatively to the project root. If the path starts with "/" it will be relative to the classpath's root.
PS:这些限制实际上在Flex SDK中.
PS: these limitations are actually in the Flex SDK.
这篇关于无法获得我的相对路径以使用FlashDevelop和Flex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!