views:

76

answers:

2

I have a handful of sprites that I am attempting to group together via addChild(). Here is some pseudo-code demonstrating what I would like to accomplish:

import nav.text.TextSprite; 

spr1:Sprite = new Sprite();
spr1.graphics.clear();
spr1.graphics.beginFill(0x000000);
spr1.graphics.drawRect(0,0,100,100);

txt1:TextSprite = new TextSprite;
txt1.text = "hello";

spr1.addChild(txt1);

//this is what isn't working:  the sprite is hidden but not the text
spr1.alpha = 0.0;

For some reason I cannot seem to get the TextSprite to draw correctly... All it is is a Sprite with a TextField added to it. I think everything is working there, but I might have something wrong w/r/t making sure all of TextSprites children are grouped correctly.

I should mention that it does position correctly; but the alpha property won't respond in the way I would expect it to. I.E., the sprite that the TextField is attached to will allow it's alpha to be set but the text remains visible.

Any thoughts?

+3  A: 

Most likely you just need to embed the font in your textfield. Try changing the x, y of spr1 and see if txt1 moves along with it. If it truly is a child then it will respond to the new position.

sberry2A
I seem to remember a co worker couldn't rotate text until the font was embedded, stands to reason alpha level would be on the same boat.
invertedSpear
Dynamic TextFields with non-embedded fonts do some whacky stuff when it comes to manipulation of their containers. For example, try putting a mask over a TextField with embedding turned off and you won't ever get to see the text.
sberry2A
ok, well i do mytextfield.embedFonts = true; right after i set the font props and the format via TextFormat(), and now i can't see the text. what am i doing wrong? do i need to do it after it's added to the display list?
jml
@sberry2A: It does respond to positional changes... I had already tested that and should have mentioned this in my original post... updating now.
jml
+1  A: 

You need to embed the font using textfield.embedFonts = true. If your text is disappearing when you do this, how are you going about embedding the font (using the Flex embed meta tag or using the Flash IDE?), check that you are not changing the font weight (setting the text to bold when you have only embedded the normal weight font) and if you are using a text format, be sure to apply the text format AFTER you set the textfield.text property. You can get around this by using textfield.defaultTextFormat.

Hanpan
Thanks. I wasn't aware that you had to embed separately. Do you have a reference for embedding using the Flash API? I get the feeling it might be more straight forward to us the Flex embed meta tag, but I would be interested in learning both methodologies.
jml
I saw this: http://www.trajiklyhip.com/blog/index.cfm/2007/7/18/Embedding-Fonts-in-Flex , which I am not quite fond of. I think I would prefer using the embed meta tag than jump out of the Flex app to kludge.
jml
jml
You can use a standard embed tag like so:[Embed(source = "../assets/copy0855.ttf", fontWeight="normal", fontFamily="Copy", mimeType="application/x-font-truetype")]private static const Copy:String;Then:_textFormat.font = "Copy";
Hanpan
This does sometimes cause Flex to show weird font parsing errors. If you get these, try adding this to the compiler parameters: -managers flash.fonts.AFEFontManager
Hanpan
Cool; I'll check it out. I am assuming that this means you don't have to write a separate style sheet to load in, as it's all included in the Embed tag...
jml