2014-12-08 1 views
0

이 코드는 옆에 텍스트가있는 확인란을 만듭니다.플래시 as3 : 체크 상자의 경우 마우스의 텍스트 색상을 변경하십시오.

누군가가 확인란 옆의 텍스트 위로 마우스를 가져 가면 텍스트가 바뀌도록 텍스트를 변경하는 방법은 무엇입니까?

더 많은 패키지가 있습니다.이 문제를 해결하는 데 도움이 필요한 경우 알려 주시면 게시 할 수 있습니다.

감사합니다.

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:*; 
} 
} 

답변

0

당신은 할 수 text_field.textColor을 사용하거나 TextFormat를 사용하여. text_field.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 

}) 

TextFormat 사용 :

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) 

}) 
+0

감사합니다 !!!! 나는 아직도 as3에 대해 많은 것을 배울 것이기 때문에 잠시만 시간을 보냈지 만 나는 그것을 작동하게했다. 또한 "text_field"를 제거해야했다. addEventListener 전에 "build.textColor"에 대한 "text_field.textColor"를 전환하십시오. –

관련 문제