Actionscript 3 使用颜色名称切换十六进制值,以将颜色选择存储为变量Flash as3

Actionscript 3 使用颜色名称切换十六进制值,以将颜色选择存储为变量Flash as3,actionscript-3,flash,switch-statement,var,Actionscript 3,Flash,Switch Statement,Var,我正在Flash Pro CS5中创建一个定制应用程序,我设置了变量来记录选项的更改。以下代码位于舞台的最顶层 //Clothes Variables var clothingType:String = ""; var gender:String = "Male"; var clothingSize:String = "Small"; var quantity:String = "1"; var design:String = ""; var colour1:String = ""; var c

我正在Flash Pro CS5中创建一个定制应用程序,我设置了变量来记录选项的更改。以下代码位于舞台的最顶层

//Clothes Variables
var clothingType:String = "";
var gender:String = "Male";
var clothingSize:String = "Small";
var quantity:String = "1";
var design:String = "";
var colour1:String = "";
var colour2:String = "";
下面是一个设计变量的示例,该设计变量被指定为单击“设计列表”上的带标签按钮(上次单击的按钮是当前显示的设计)

我使用十六进制值输出(动态文本框,其中显示上次单击的样例十六进制值)来控制该颜色1和2值,如果语句无效。以下所有代码都在Ink_mc中,mc包含所有墨水选项,每个设计都有单独的框架(6个框架对应6个设计,每个设计都有自己的调色板、设计mc和控制颜色变化的代码,但它们共享以下代码,因为它位于跨越所有6个框架的图层上)

这是我的一个颜色选择器

//set up a listener for color change events dispatched from the color picker
//see as function layer for function
Pre_pal1.addEventListener(ColorPicker.COLOR_CHANGE, handlePre1ColorChangeEvents);
Pre_pal2.addEventListener(ColorPicker.COLOR_CHANGE, handlePre2ColorChangeEvents);

//this function is called whenever the user clicks the palette to change colors
function handlePre1ColorChangeEvents(ev:Event):void {
    //output the hex value to the screen
    hexValue.text = ColorPicker(ev.currentTarget).webValue;

    //output the RGB values to the screen
    rValue.text = String(ColorPicker(ev.currentTarget).red);
    gValue.text = String(ColorPicker(ev.currentTarget).green);
    bValue.text = String(ColorPicker(ev.currentTarget).blue);

    //change the colour of the ladybugs shell to the current palette color
    ColorPicker(ev.currentTarget).transformToCurrentColor(Pre1);
}

//this function is called whenever the user clicks the palette to change colors
function handlePre2ColorChangeEvents(ev:Event):void {
    //output the hex value to the screen
    hexValue2.text = ColorPicker(ev.currentTarget).webValue;

    //output the RGB values to the screen
    rValue2.text = String(ColorPicker(ev.currentTarget).red);
    gValue2.text = String(ColorPicker(ev.currentTarget).green);
    bValue2.text = String(ColorPicker(ev.currentTarget).blue);

    //change the colour of the ladybugs shell to the current palette color
    ColorPicker(ev.currentTarget).transformToCurrentColor(Pre2);
}
请记住,我将需要为color1和color2变量执行此操作,我制作了一个相同的十六进制值显示(仅4个动态文本框显示每个值,十六进制、右值、gValue、bValue),称为hexValue2、右值2等等

因此,我正在寻找一种基于颜色名称设置变量的方法,这些颜色名称由最后显示的十六进制值设置。对不起,如果我用一种天真的方式来处理这个问题,希望有一个简单的解决方案

如果您想了解更多关于文件设置的信息或其他信息,请告诉我, adam@one69a.com.


谢谢大家!

只是想抓住你想要的。您提供的代码起作用,它们从托盘中拾取颜色,生成hexvalue、rgbvalue和colorname值。现在你想让它反过来工作。当他们输入颜色名称时,您希望生成hexvalue和rgbvalue?很抱歉,这是对im后结果的模糊描述。在应用程序的末尾将是一个页面,显示所有已更改的选项,我使用变量来存储信息,希望可以切换到我可以设置的易读内容。谢谢回复!您需要更改的一件事是代码中带有colorname的=和==符号。if语句需要==(因为它意味着等于)电影。命令需要=(因为它意味着将值设置为)。有些人现在错了。
if (hexValue.text = "02ADDB") 
    {
        MovieClip(root).colour1 == "Light Blue";
}
if (hexValue.text == "067ABB")
    {
        MovieClip(root).colour1 = "Blue B";
        }
if (hexValue.text == "06579E")
    {
        MovieClip(root).colour1 == "Ultra Blue";
        }
if (hexValue.text == "34328A")
    {
        MovieClip(root).colour1 = "Purple";
        }
if (hexValue.text == "FFF100")
    {
        MovieClip(root).colour1 = "Mid Yellow";
        }
if (hexValue.text == "FFCF48")
    {
        MovieClip(root).colour1 = "Yellow R";
        }
if (hexValue.text == "B1D392")
    {
        MovieClip(root).colour1 == "Mid Green";
        }
if (hexValue.text == "1ABO65")
    {
        MovieClip(root).colour1 == "Green B";
        }
if (hexValue.text == "FAA9A7")
    {
        MovieClip(root).colour1 == "Glow Pink";
        }
if (hexValue.text == "F174A7")
    {
        MovieClip(root).colour1 == "Glow Red";
        }
if (hexValue.text == "B83O8B")
    {
        MovieClip(root).colour1 == "Rose";
        }
if (hexValue.text == "D41F2E")
    {
        MovieClip(root).colour1 == "Bright Red";
        }
//set up a listener for color change events dispatched from the color picker
//see as function layer for function
Pre_pal1.addEventListener(ColorPicker.COLOR_CHANGE, handlePre1ColorChangeEvents);
Pre_pal2.addEventListener(ColorPicker.COLOR_CHANGE, handlePre2ColorChangeEvents);

//this function is called whenever the user clicks the palette to change colors
function handlePre1ColorChangeEvents(ev:Event):void {
    //output the hex value to the screen
    hexValue.text = ColorPicker(ev.currentTarget).webValue;

    //output the RGB values to the screen
    rValue.text = String(ColorPicker(ev.currentTarget).red);
    gValue.text = String(ColorPicker(ev.currentTarget).green);
    bValue.text = String(ColorPicker(ev.currentTarget).blue);

    //change the colour of the ladybugs shell to the current palette color
    ColorPicker(ev.currentTarget).transformToCurrentColor(Pre1);
}

//this function is called whenever the user clicks the palette to change colors
function handlePre2ColorChangeEvents(ev:Event):void {
    //output the hex value to the screen
    hexValue2.text = ColorPicker(ev.currentTarget).webValue;

    //output the RGB values to the screen
    rValue2.text = String(ColorPicker(ev.currentTarget).red);
    gValue2.text = String(ColorPicker(ev.currentTarget).green);
    bValue2.text = String(ColorPicker(ev.currentTarget).blue);

    //change the colour of the ladybugs shell to the current palette color
    ColorPicker(ev.currentTarget).transformToCurrentColor(Pre2);
}