Search code examples
actionscript-3apache-flexflex4.5flashdevelop

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


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>

Solution

  • 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.