从flex文件系统加载图像

时间:2011-12-13 16:41:56

标签: flex image filesystems load

我有以下内容:

<s:Image  source="{path}/imageName"/>

如何确定从文件系统加载图像的路径 C:\ Users \ sstauross \ Desktop ??

2 个答案:

答案 0 :(得分:1)

编辑:如果要选择特定路径,用户必须首先使用FileSystemList

自行确认路径
<?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">

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            private var userPath:String;

            protected function button_clickHandler(event:MouseEvent):void
            {
                userPath = fsList.selectedPath;
            }
        ]]>
    </fx:Script>

    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <mx:FileSystemList id="fsList"/>

    <s:Label text="{fsList.selectedPath}"/>

    <s:Button label="Confirm folder selection" click="button_clickHandler(event)"/>

</s:WindowedApplication>

这是一种方法

<?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="creationCompleteHandler(event)">

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            [Bindable]
            private var desktopPath:String;

            protected function creationCompleteHandler(event:FlexEvent):void
            {
                desktopPath = File.desktopDirectory.nativePath.toString();
            }

        ]]>
    </fx:Script>

    <mx:Image source="{desktopPath}/myFile.jpg"/>

</s:WindowedApplication>

答案 1 :(得分:0)

我所看到的答案很简单,因为我把

<s:Image  source="C:\Users\sstauross\Desktop\imageName"/>

而不是

<s:Image  source="C:/Users/sstauross/Desktop/imageName"/>

注意“\”而不是“/"...

非常感谢您的回答!