Flash:如何在AS3中动态/按动作更改文本字段的textFormat?

时间:2009-09-08 15:59:16

标签: flash actionscript-3 arrays text

嗨:)今天我的问题是如何在文本字段中更改textFormat。

我有一个白色文字的textFormat和一个绿色文字的文本格式,在按钮翻转时我需要将textField上的textFormat交换为< strong>绿色文字。 textFields从数组中获取他们的.text数据,使事情变得复杂......


数组,文本格式,按钮,TextField创建代码:

var cataText:Array = [] //My text array

// Text Formats
var a12 = new TextFormat();
    a12.font = "Arial";
    a12.size = 12;
    a12.color = 0xFFFFFF;

var a12Green = new TextFormat();
    a12Green.font ="Arial";
    a12Green.size = 12;
    a12Green.color = 0xA7D23F;


// Create the Nav Buttons -----------------------------------
function createNav()
{
     for (var i:Number = 0; i < myXMLArray.lenght; i++)
         navButton = new NavButton();
         navButton.name = "button" +i;
         navButton.x = i * (SIZE + SPACING);
         navButton.y = buttonY;
         thumbsMov.addChild(navButton);

         buttons.push(navButton)
         buttons[i].addEventListener(MouseEvent.MOUSE_UP, handleButtonClick);
         buttons[i].addEventListener(MouseEvent.ROLL_OVER, handleButtonOver);
         buttons[i].addEventListener)MouseEvent.ROLL_OUT, handleButtonOff);
         buttons[i].useHandCursor = true;

     var traceText:TextField = new TextField();
         traceText.defaultTextFormat = a12;
         traceText.selectable = false;
         traceText.mouseEnabled = false;
         traceText.x = i * (SIZE + SPACING);
         traceText.y = 186;
         traceText.width = 116;
         traceText.height = 20;
         traceText.text = myXMLArray[i].id; // <setting the text
         thumbsMov.addChild(traceText);

         cataText.push(traceText);  // <The array my text is getting placed in

} 

}


按钮侦听器代码以及我正在尝试更改textFormat的位置

// Button Listener  -----------------------------------
function handleButtonOver(event:MouseEvent):void
{
    var button:NavButton = event.target as NavButton;
    if(button)
       button.nextFrame()
       thumbsMov.traceText.defaultTextFormat = a12Green;  //< trying to assign new textFormat
       thumbsMov.traceText.text = cataText[0].text; // < figured this is how I would set the text again...
       trace(cataText[0].text);
}

trace(cataText [0] .text); //&lt;只有当我注释掉它上方的两行时才会追踪出来:(因为如果上面的两行没有被注释掉的话,我会在翻转时得到以下错误:

我的错误: TypeError:错误#1010:术语未定义且没有属性。     在test2_fla :: MainTimeline / handleButtonOver()

我猜我可能需要某种类型的listenerEvent?听取某种变量的变化,然后换掉textFormat,但我不确定如何以这种方式进行。

1 个答案:

答案 0 :(得分:0)

如果您更改

会发生什么
thumbsMov.traceText.defaultTextFormat = a12Green;

thumbsMov.traceText.setTextFormat(a12Green);