如何将Flex 3 ColorPicker Value存储在变量中并将变量绑定到textInput

时间:2009-12-11 12:12:53

标签: flex binding variables textinput concatenation

有人可以帮帮我吗? 我想在变量中存储hex colorPicker值,然后将var backout的值转换为textInput。 textInput只是为了看到我选择的女巫六色。

因此意味着在textInput中看到0x000000。

我现在所做的非常简单,我已将flex colorPicker直接绑定到我的textInput。但我想先将colorPicker中的值存储在var中,然后再将其吐出到textInput中以查看我选择的值。

当我选择一个以数字0开头的颜色值时,它会在数字的开头删除0,并且只吐出大于0的数字。(000033变为33,FF0000保持FF0000)。 我想要捕获整个值或者写一些函数来计算丢弃了多少0并将其与0x连接起来。将all存储到var中并将其绑定到flex TextInput。但我不知道该怎么做。有人知道我必须做什么吗?

这就是我所拥有的。

<?xml version="1.0" encoding="utf-8"?>
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="vertical" 
           width="100%" 
           height="100%">


<mx:ColorPicker id="bgColor"/>
<mx:TextInput text="{bgColor.selectedColor.toString(16)}"/>

<mx:Canvas width="100" height="100" backgroundColor="{bgColor.selectedColor}"/>

</mx:Module>

感谢

DJ

1 个答案:

答案 0 :(得分:2)

colorchosers选择的颜色是一个uint,你需要做的是将其转换为十六进制。我为你做了一个快速谷歌,并找到了解决方案here

这是我自己的看法

<mx:ColorPicker id="bgColor" change="colourChange()"/>
<mx:TextInput id="txtColour" />

<mx:Canvas width="100" height="100" backgroundColor="{bgColor.selectedColor}"/>

<mx:Script>
    <![CDATA[

        private function colourChange():void
        {
           var hexString:* = bgColor.selectedColor.toString(16).toUpperCase();
           var cnt:int = 6 - hexString.length;
           var zeros:String = "";

           for (var i:int = 0; i < cnt; i++) 
           {
                zeros += "0";
           }

           txtColour.text =  "#" + zeros + hexString;
        }

    ]]>
</mx:Script>

请原谅上面的错误代码格式!!!