Actionscript 3 Flash as3:更改复选框鼠标上文本的颜色

Actionscript 3 Flash as3:更改复选框鼠标上文本的颜色,actionscript-3,flash-cs5,Actionscript 3,Flash Cs5,因此,这段代码创建了一个复选框,旁边有一些文本 当有人将鼠标移到复选框旁边的文本上时,如何使文本改变颜色 有更多的软件包与此一起…如果需要帮助解决这个问题,请让我知道,我也可以张贴这些 谢谢 package { import flash.display.*; import flash.events.*; import flash.geom.*; import flash.text.*; public class Checkbox extends flash.display.Sprite {

因此,这段代码创建了一个复选框,旁边有一些文本

当有人将鼠标移到复选框旁边的文本上时,如何使文本改变颜色

有更多的软件包与此一起…如果需要帮助解决这个问题,请让我知道,我也可以张贴这些

谢谢

package 
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;

public class Checkbox extends flash.display.Sprite
{
    public function Checkbox(arg1:uint, arg2:uint,
    arg3:String, arg4:Boolean, arg5:Boolean=true, arg6:*=null)
    {
        super();
        this.label = arg3;
        this.selected = arg4;
        this.x = arg1;
        this.y = arg2;
        this.enabled = arg5;
        this.callback = arg6;
        build();
        return;
    }

    public function update():void
    {
        build();
        return;
    }

    internal function handler(arg1:flash.events.MouseEvent):void
    {
        if (enabled) 
        {
            selected = !selected;
            setSelected(selected);
        }
        if (callback != null) 
        {
            callback();
        }
        return;
    }

    public function build():void
    {
        var labelText:*;
        var labelFmt:*;

        var loc1:*;
        graphics.clear();
        Utils.clearDisplayList(this);
        butn = new SimpleButton();
        addChild(butn);
        box = new Shape();
        var loc2:*;
        with (loc2 = box.graphics) 
        {
            lineStyle(1);
            beginFill(bgColor);
            drawRect(0, 0, 12, 12);
            endFill();
        }
        boxWithCheckmark = new Shape();
        with (loc2 = boxWithCheckmark.graphics) 
        {
            lineStyle(1);
            beginFill(bgColor);
            drawRect(0, 0, 12, 12);
            endFill();
            lineStyle(2, tickColor);
            moveTo(3, 6);
            lineTo(4, 10);
            lineTo(10, 3);
        }
        labelFmt = new TextFormat();
        with (loc2 = labelFmt) 
        {
            color = labelColor;
            font = "_sans";
            size = 12;
        }
        labelText = new TextField();
        with (loc2 = labelText) 
        {
            autoSize = TextFieldAutoSize.LEFT;
            selectable = false;
            text = label;
            setTextFormat(labelFmt);
            x = 16;
            y = -3;
        }
        this.addChild(labelText);
        setSelected(selected);
        addEventListener(MouseEvent.CLICK, handler);
        return;
    }

    public function setSelected(arg1:Boolean):*
    {
        this.selected = arg1;
        if (selected) 
        {
            var loc1:*;
            butn.hitTestState = loc1 = boxWithCheckmark;
            butn.downState = loc1 = loc1;
            butn.overState = loc1 = loc1;
            butn.upState = loc1;
        }
        else 
        {
            butn.hitTestState = loc1 = box;
            butn.downState = loc1 = loc1;
            butn.overState = loc1 = loc1;
            butn.upState = loc1;
        }
        return;
    }

    public var enabled:Boolean;

    internal var boxWithCheckmark:flash.display.Shape;

    public var bgColor:*=15658734;

    public var tickColor:*=3355443;

    internal var box:flash.display.Shape;

    internal var butn:flash.display.SimpleButton;

    public var labelColor:*=0;

    public var label:String;

    public var selected:Boolean;

    public var callback:*;
}
}

您可以使用
text\u field.textColor
TextFormat
执行此操作

使用
text\u字段。textColor

var hover_color:Number = 0xff0000
var out_color:Number = 0x666666

text_field.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent)
{
    text_field.textColor = hover_color
})
text_field.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent)
{
    text_field.textColor = out_color

})
var text_format:TextFormat = new TextFormat()
    text_format.color = out_color

text_field.defaultTextFormat = text_format

text_field.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent)
{
    text_format.color = hover_color
    text_field.setTextFormat(text_format)
})
text_field.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent)
{
    text_field.setTextFormat(text_field.defaultTextFormat)

})
使用
TextFormat

var hover_color:Number = 0xff0000
var out_color:Number = 0x666666

text_field.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent)
{
    text_field.textColor = hover_color
})
text_field.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent)
{
    text_field.textColor = out_color

})
var text_format:TextFormat = new TextFormat()
    text_format.color = out_color

text_field.defaultTextFormat = text_format

text_field.addEventListener(MouseEvent.MOUSE_OVER, function(e:MouseEvent)
{
    text_format.color = hover_color
    text_field.setTextFormat(text_format)
})
text_field.addEventListener(MouseEvent.MOUSE_OUT, function(e:MouseEvent)
{
    text_field.setTextFormat(text_field.defaultTextFormat)

})

谢谢我花了一段时间,因为我还有很多关于as3的知识要学习,但我让它工作了…我还不得不在addEventListener之前删除“text\u field.”,并将“text\u field.textColor”切换为“build.textColor”。