Dmitry
Dmitry

Reputation: 185

TextArea text formatting not changing in Flash CS5

Prologue I am studying Flash and want to make a video player with where you can change video and the corresponding subtitles with a click on either "forward" or "back" button.

So far I have created 2 arrays of video files ("[videos]") and text strings ("[captions]"). By clicking on one of the buttons, the video in the FLVPlayback component changes as well as the the subtitles-text in the TextArea.

However I have a problem with text formatting.

I use the following functions for button click:

   function playNextVideo():void
   {
   if (currentVideo < videos.length-1)
    {
    currentVideo++;
    playCurrentVideo();
    }
   }

   function playCurrentVideo():void
   {
    textCaption.textField.defaultTextFormat = newFormat;
    textCaption.textField.text=captions[currentVideo];
    myVideo.source = videos[currentVideo];
    myVideo.play();
   }

The newFormat is a simple TextFormat variable:

var newFormat:TextFormat = new TextFormat();

newFormat.color = 0x0000C9;
newFormat.size = 18;
newFormat.italic = true;

I execute playCurrentVideo() to start the video playback.

The Problem My problem is that the format changes only when I click the button, but it is not applied for the first subtitle.

So, for the first video I get a plain text, with black color, not italic and not with size "18". However, if I click on "forward" button (and thus execute the playCurrentVideo() again), the format will change. If I then will try to go back to the first video, the text will now be formatted.

So my question is - what causes this condition and how to handle it?

Upvotes: 0

Views: 2344

Answers (2)

goliatone
goliatone

Reputation: 2174

If the TextArea you are using is one of flash components then you need to call:

textCaption.setStyle( "textFormat", newFormat );

Your code would look now as:

 function playCurrentVideo():void {
textCaption.setStyle( "textFormat", newFormat );
textCaption.text=captions[currentVideo];
myVideo.source = videos[currentVideo];
myVideo.play();

}

Upvotes: 1

weltraumpirat
weltraumpirat

Reputation: 22604

I suspect it has something to do with the way TextField is implemented. When you change a TextField's properties, you sometimes have to wait one frame until the changes apply. Try to set defaultTextFormat = newFormat at the time the TextField is instantiated, and/or setTextFormat(newFormat) after the text is changed.

Upvotes: 1

Related Questions