Can't get my relative paths to work with flashDevelop and flex

落爺英雄遲暮 提交于 2019-12-11 13:45:08

问题


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>

回答1:


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.

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: these limitations are actually in the Flex SDK.




回答2:


If I remember correctly the source="../img/Koala.jpg" is processed at runtime while the embed directive is processed at compile time. So the working directory is different which causes the source="" to fail.

Does the following work :

<s:Image id="imgstage" source="img/Koala.jpg" y="0" x="0"/>

Assuming the img folder is next to your swf file it should work.




回答3:


In FlashDevelop, whatever files that you want to keep outside the SWF have to be placed in bin folder.



来源:https://stackoverflow.com/questions/13298843/cant-get-my-relative-paths-to-work-with-flashdevelop-and-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!