views:

27

answers:

2

I have text fields that I need to set as both autosize and bold in ActionScript. For some reason, when I apply the bold formatting, the autosize=true is lost. From what I can tell, I am doing everything in the correct order. Any thoughts on what is going on are hugely appreciated. Thanks!

Here is the relevant code:

var categoryMenu:MovieClip = _root.createEmptyMovieClip("categoryMenu", 1005);

var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;

for (var i:Number = 0; i<numCat; i++) {
    var menu:MovieClip = categoryMenu.attachMovie("menu", "menu"+i,i);
    menu._txt.txt.autoSize = true;
    menu._txt.txt.text = gallData.getMenuGall.name[i];
            //if i comment out the following line, the autosize works.
            //if i leave it in, the autosize is lost.  but i can't put this line
            //before the autosize or i lose the bold
    menu._txt.txt.setTextFormat(my_fmt);
     ...
     }
+2  A: 

autoSize is not a boolean, it's a string. See the documentation.

Cory Petosky
and unless you need to change your text format, menu._txt.txt.defaultTextFormat = my_fmt; may be a better solution for you.
pferdefleisch
Thanks for the reply. I should have mentioned that I had tried setting autoSize = "left" and it exhibits the same behavior. Both work when I do not include the bold assignment. I have also tried menu._txt.txt.defaultTextFormat = my_fmt to no avail. Regardless of where I place that line, it does not create the bold formatting.Am I missing something conceptually here? Autosize is applied to the text field, and the bold formatting is applied to the text, right? So why would the bold impact the formatting of the text field?
Kate
A: 

what's your environment? If you're working with Flash CS? Is is possible that the text formatting defined in your code is conflicting with the textfield instance in your MovieClip?

PatrickS
Thanks for the tip, but from what I can tell there shouldn't be a conflict. I'm working with CS5 and the movieclip is created dynamically in the action script:var categoryMenu:MovieClip = _root.createEmptyMovieClip("categoryMenu", 1005);So, as far as I can tell, there shouldn't be any conflict. I haven't been able to find anything in the documentation about default settings upon creating a new movie clip, beyond the position of the clip itself. It just seems so strange to me that both formatting lines work independently of one another.
Kate
hmmm, your code doesn't show how the TextField is created, that's why I thought that in menu._txt.txt , "txt" was an instance of a TextField you had on stage. It wouldn't be about MovieClip default settings though, rather the TextField class default settings , but that wouldn't be a source of conflict.
PatrickS
thanks for the help, patrick. this thing is driving me nuts! :)
Kate
I think the problem is not with bold and autosize, rather , when you set the bold property some form of conflict is triggered which disables autosize. Can you do a test by creating a basic Textfield in another document for instance, some form of "Hello World" test and see what happens? You shouldn't be able to reproduce the error with a very basic setup... well, I hope not :) Basically , try to simplify your setup , if the error is not reproduced, start adding new elements until the error occurs again.
PatrickS
You're right. In a simple file, they both work together. I'll start adding other elements back in to try to find the culprit.Thanks!
Kate