1

如何使用动作脚本更改列表组件的背景颜色

4

1 回答 1

2

这是从 的contentBackgroundColorstyle 属性定义的s:List

列表

MXML 示例:

在 MXML 中,设置组件的contentBackgroundColor属性s:List

<?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"
               xmlns:mx="library://ns.adobe.com/flex/mx">

    <s:List contentBackgroundColor="0xabcdef">
        <s:dataProvider>
            <s:ArrayList>
                <fx:String>Item 1</fx:String>
                <fx:String>Item 2</fx:String>
                <fx:String>Item 3</fx:String>
            </s:ArrayList>
        </s:dataProvider>
    </s:List>

</s:Application>

动作脚本示例:

在 ActionScript 中,设置样式属性:setStyle("contentBackgroundColor", 0xabcdef);

<?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"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               creationComplete="creationCompleteHandler(event)">

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

            protected function creationCompleteHandler(event:FlexEvent):void
            {
                list.setStyle("contentBackgroundColor", 0xabcdef);
            }
        ]]>
    </fx:Script>

    <s:List id="list">
        <s:dataProvider>
            <s:ArrayList>
                <fx:String>Item 1</fx:String>
                <fx:String>Item 2</fx:String>
                <fx:String>Item 3</fx:String>
            </s:ArrayList>
        </s:dataProvider>
    </s:List>

</s:Application>

这也可以通过为列表创建一个皮肤类来完成。

于 2012-07-21T06:39:47.793 回答