简体   繁体   English

文本输入读取颜色选择器值AS3

[英]Text Input reading a Color Picker value AS3

So I am trying to code a Text Input to display the decimal color value. 所以我试图编码文本输入以显示十进制颜色值。 I have one color picker and one text input. 我有一个颜色选择器和一个文本输入。 Here is my code. 这是我的代码。

//Import
import flash.display.MovieClip;
import fl.controls.TextInput;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
//Variables
var ColorPickerThing:ColorPicker

this.ColorPickerThing.addEventListener(ColorPickerEvent.CHANGE,ColorCode);

function ColorCode(event:ColorPickerEvent):void { 
    this.ColorValue.text = this.ColorPickerThing.selectedColor;
}

So in the end I want the decimal value for any color I pick to show up in the text input. 因此,最后我希望我选择的任何颜色的十进制值都显示在文本输入中。

http://i.stack.imgur.com/1P86M.png http://i.stack.imgur.com/1P86M.png

So if anyone could help it would be greatly apreciated. 因此,如果有人可以提供帮助,它将非常感激。 :) :)

I need help as this doesn't work. 我需要帮助,因为这不起作用。 :/ I was hoping I could make it on my own but sadly my knowledge is limited. :/我希望自己能做到,但可惜我的知识有限。 So I need help on making it work. 所以我需要帮助使其工作。

I think the problem is that you haven't properly assigned any instance names and wired them to your variables in your code properly. 我认为问题在于您没有正确分配任何实例名称,也没有将它们正确地连接到代码中的变量中。

Try this code: 试试这个代码:

//Import
import flash.display.MovieClip;
import fl.controls.TextInput;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
//Variables
var ColorPickerThing:ColorPicker = my_color_picker;

this.ColorPickerThing.addEventListener(ColorPickerEvent.CHANGE, ColorCode);

function ColorCode(event: ColorPickerEvent):void {
    this.my_color_picker_value.text = this.ColorPickerThing.selectedColor.toString();
}

And on your stage, set the instance name of the text field you are using to display the selected color to be 'my_color_picker_value' and set the instance name of the actual color picker component to be 'my_color_picker'. 然后在您的舞台上,将用于显示所选颜色的文本字段的实例名称设置为“ my_color_picker_value”,并将实际颜色选择器组件的实例名称设置为“ my_color_picker”。

Using your code as a starting point, I was able to create a working example in Flash CC using the code I've provided to you above. 使用您的代码作为起点,我能够使用上面提供的代码在Flash CC中创建一个有效的示例。 In my example, when you select a color in the color picker component, the decimal value of that color is shown in the text field. 在我的示例中,当您在颜色选择器组件中选择一种颜色时,该颜色的十进制值将显示在文本字段中。 Is that what you wanted? 那是你想要的吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM