Skip to main content
Inspiring
August 6, 2008
Answered

Sprites/Containers - Alpha Property

  • August 6, 2008
  • 4 replies
  • 424 views
I have created a container for placing a number of objects and would like to globally set the alpha to 50%.

Why can't I just do:

container.alpha = 50;

(container is a sprite)

Any insight would be appreciated
This topic has been closed for replies.
Correct answer theatlasman
Thanks, it worked!

4 replies

theatlasmanAuthorCorrect answer
Inspiring
August 6, 2008
Thanks, it worked!
August 6, 2008
Also,

If you don't want to embed the font, create a rectangle graphic the same size as the textfield, set the alpha to .5 and add it as a child to the container.

var rectangle:Sprite = new Sprite()
rectangle.graphics.lineStyle(1,0x000000,0)
rectangle.graphics.beginFill(0xFFFFFF,0.5)
rectangle.graphics.drawRect(0,0,1000,100)
rectangle.graphics.endFill();

container.addChild(myText);
container.addChild(rectangle)
August 6, 2008
You'll need to embed the font and include the font in your library to make it work. On your library panel, click the little down arrow with 3 lines beside it (on the top right) and select New Font. Select your font and add it to the Library, and then make sure to check "Export for Actionscript" on the linkage. After that, make sure to set myText.embedfonts = true.

Hope that helps!

Cheers,
FlashTastic
August 6, 2008
In Actionscript 3.0, alpha is a percentage, not an integer. The value will always be between 0 and 1. You'll need to change it to container.alpha = 0.5;

Cheers,
FlashTastic
Inspiring
August 6, 2008
This has no impact on the text field that is contained by the Sprite. Thanks.