使用带有Icon ItemRenderer的Multi DPI BitmapSource - 附带测试用例和屏幕截图

时间:2013-06-03 15:11:35

标签: flex flex4 flex4.5 flex4.6 flex-mobile

在下面简单的Flex移动测试案例中,为什么列表中的图标不可见?

截图:

enter image description here

App.mxml (只需添加到Flash Builder 4.7中的空白Flex移动项目):

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               applicationDPI="160">
    <fx:Declarations>
        <s:MultiDPIBitmapSource id="EN_ICON"
                source160dpi="@Embed('low-res/en_US.png')"
                source240dpi="@Embed('mid-res/en_US.png')"
                source320dpi="@Embed('high-res/en_US.png')"/>
        <s:MultiDPIBitmapSource id="RU_ICON"
                source160dpi="@Embed('low-res/ru_RU.png')"
                source240dpi="@Embed('mid-res/ru_RU.png')"
                source320dpi="@Embed('high-res/ru_RU.png')"/>
        <s:MultiDPIBitmapSource id="DE_ICON"
                source160dpi="@Embed('low-res/de_DE.png')"
                source240dpi="@Embed('mid-res/de_DE.png')"
                source320dpi="@Embed('high-res/de_DE.png')"/>
    </fx:Declarations>

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            private const LANGUAGES:ArrayCollection = new ArrayCollection([
                { icon: EN_ICON, locale: 'en_US', label: 'English' },
                { icon: RU_ICON, locale: 'ru_RU', label: 'Русский' },
                { icon: DE_ICON, locale: 'de_DE', label: 'Deutsch' }
            ]);
        ]]>
    </fx:Script> 

    <s:List 
        width="100%" 
        height="100%"
        dataProvider="{LANGUAGES}">
        <s:itemRenderer>
            <fx:Component>
                <s:IconItemRenderer labelField="label" iconField="icon" />
            </fx:Component>
        </s:itemRenderer>
    </s:List>
</s:Application>

图标(由用户koppi @ openclipart.org提供并放置在子目录中:src / low-res,src / mid-res,src / high-res):

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:2)

问题是在创建3个LANGUAGES对象之前正在创建MultiDPIBitmapSource数组集合。实际上,dataProvider中的每个元素在null字段中都有icon

副手,我不知道组件生命周期中的哪一点会创建<fx:Declarations>标签中的对象,但我知道它们应该在“creationComplete”事件发生时创建被派遣。事实上,正如OP已经确认的那样,当调度“initialize”事件时,声明标记中的对象已经被创建。

如果在“creationComplete”事件处理程序中创建LANGUAGES数组集合,它将正常工作。

答案 1 :(得分:-1)

我不确定这是否能解决您的问题,但每当我使用Embed时,我都会这样使用它:

@Embed(source='GenericImageFileName.png')