简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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