开发者

setting selectedColor in a colorpikcer

How do you set the selectedColor of a colorpicker when you bind data from a database?

I have a bindable vari开发者_Python百科able, objProject, with a field called color and it has a color code such as #ff00ff in it. I want to set the selectedColor. I tried to cast the color as a uint, but no joy.

objProject = cmbProject.selectedItem;
c = uint(objProject.color);

<mx:ColorPicker id="graphColor"  x="17" y="219" width="128" height="40"
    selectedColor="{c}" editable="true"  />

I did try selectedColor="{objProject.color}" and that didn't work either.

Suggestions?


I don't understand why you can't do this:

objProject = cmbProject.selectedItem;
graphColor.selectedColor = uint(objProject.color);

Is there a specific reason you need to use binding in this case?


I see - you have a hex value -

Try this :

Number('0x' + yourColorString.replace('#','') );

The 0x notation specifies a hex radix, thus when it is evaluated it will convert the hex value into a numerical one. Yes, you could replace the # with the 0x instead, but doing it this works even if they did not include the hash.

Going the other way is easy as well (from number back to hex):

String( '#' + yourNumericValue.toString(16) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜