How to set an image's source in a Flex stylesheet (not Embed)

假装没事ソ 提交于 2020-01-05 03:32:44

问题


This works:

<mx:Image styleName="image" source="done.png">
</mx:Image>

This doesn't:

<fx:Style>
    @namespace mx "library://ns.adobe.com/flex/mx";
    @namespace s "library://ns.adobe.com/flex/spark";

    .image {
        source : url("done.png")
    }

</fx:Style>
<mx:Image styleName="image" >
</mx:Image>

Driving me crazy. How it this supposed to be done?

Same results if I do:

.image {
    source : "done.png"
}

Complete source code is:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           xmlns:s="library://ns.adobe.com/flex/spark"
           minWidth="636" minHeight="389" width="636" height="389"
           >

<fx:Style>
    @namespace mx "library://ns.adobe.com/flex/mx";
    @namespace s "library://ns.adobe.com/flex/spark";

    .image {
        source : "done.png"
    }

</fx:Style>
<mx:Image styleName="image" >
</mx:Image>
</s:Application>

回答1:


mx:Image's source is not a style but property. It can't be set using CSS directly. Try to use something like:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    xmlns:s="library://ns.adobe.com/flex/spark"
    minWidth="636" minHeight="389" width="636" height="389"
    >

    <fx:Style>
        @namespace mx "library://ns.adobe.com/flex/mx";
        @namespace s "library://ns.adobe.com/flex/spark";

        s|Application {
            image-source: Embed(source="done.png");
        }

    </fx:Style>
    <mx:Image source="{getStyle('imageSource')}" >
    </mx:Image>
</s:Application>


来源:https://stackoverflow.com/questions/6059983/how-to-set-an-images-source-in-a-flex-stylesheet-not-embed

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