Flash: How to change textFormat textboxes on the fly / per action in AS3?

Hi :) My question today is how to change the textFormat in the textbox.

I have a textFormat with white text and one that has green text , when a button rolls over, I need to change this textFormat on my textbox to one that has green text . TextFields get their .text data from an array to complicate matters ...


Arrays, text formats, buttons, text box creation code:

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

} 

      

}


Button listener code and where i am trying to change 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); // <this will only be traced if I comment out the 2 lines above it :( because I get the below error on rollover if the 2 lines above are not commented out:

My error: TypeError: Error # 1010: The term is undefined and has no properties. at test2_fla :: MainTimeline / handleButtonOver ()

I am guessing I might need some kind of listenerEvent? To listen to some kind of variable change and then change the textFormat, but I'm not sure how.

+2


source to share


1 answer


What happens if you change

thumbsMov.traceText.defaultTextFormat = a12Green;

      



to

thumbsMov.traceText.setTextFormat(a12Green);

      

0


source







All Articles