English 中文(简体)
How to store Flex 3 ColorPicker Value in a variable and bind the variable to a textInput
原标题:

Can anybody help me out? I would like to store a hex colorPicker value in a variable and then cast the value of the var backout to a textInput. The textInput is just to see witch hexcolor i have choosen.

thus meaning seeing 0x000000 in the textInput.

what i ve done now is pretty simple i have bound the flex colorPicker directly to my textInput. but i want to store the value from the colorPicker in a var first and than spit it backout to the textInput to see the value that i have picked.

When i pick a color value that begins with the number 0 it drops the 0 s at the beginning of the number and only spits out the numbers greater than 0. (000033 becomes 33, FF0000 stays FF0000). I want to catch the whole value or write some kind a function to figure out how many 0 s got dropped and concatenate it together with 0x. Store that all into a var and bind it to the flex TextInput. But i don t know how to do that. Does anybody know what i must do?

This is what i ve got.

<?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>

Thank

DJ

最佳回答

The colorchosers selected color is a uint and what you need to do is covert this to hex. I did a quick google for you and found a solution here

Here is my own take on it

<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>

Excuse the bad code formatting above!!!

问题回答

暂无回答




相关问题
Disable button tooltip in AS3

I want to disable the tooltip on certain buttons. The tooltip manager seems to be an all or nothing solution. Is it possible to disable the tooltip for just one or two buttons?

Multiple Remote call made simultenously

I was making multiple remote calls and they are done sequentially and when I am getting a result event back it s triggering calls to all the methods with ResultEvent as an argument . I am supposed to ...

Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Clearing RSL in Cache

I have built a flex application which has a "main" project and it is assosciated with a few RSL s which are loaded and cached once i run my "main" application. The problem i am facing is that the ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签