Be a Supporter!

AS: Text Fadeout

  • 1,003 Views
  • 6 Replies
New Topic Respond to this Topic
LesPaulPlayer
LesPaulPlayer
  • Member since: May. 18, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
AS: Text Fadeout 2007-04-17 10:44:15 Reply

AS: Mane

This tutorial will cover how to make a textfield fade out using actionscript only. If you've ever tried to make a textfield fade out using the textfield._alpha property, you probably did something wrong, and your textfield probably just went from alpha 100 to alpha 0. That's because you need to embed fonts to make it work.

Fading text is a great effect in movies and games. In games, you may want to fade a message or a score or something. It is very inconvenient to have to make a symbol for each new message or score that you need. In my most recent game, Final Tank, I used fading text a lot. Here is how to do it.

First, you need to add a new font symbol to the library. On the upper right corner of the library, there is a drop down menu. Click it and select 'New Font'.

Its in the same place as New Video

In the drop down menu that says "Font", select the font of your textfield. In the text area labeled "Name", type Font1 . If you want the font to be bold or italicized, check the boxes. When everything is good, click ok. Right click on the Font in the library and select Linkage. Click on 'Export for Actionscript' and make sure that the identifier is Font1.

Now for some action. script that is.

createTextField("textfield", 1, 275, 200, 200, 25);
// creates a textfield
var fmt:TextFormat = new TextFormat();
fmt.font = "Font1";
//creates a text format and associates the font in the library with it.
textfield.embedFonts = true;
//tells the textfield to include fonts in the library.
textfield.text = "alpha fade out";
//sets the text of the textfield.
textfield.setTextFormat(fmt);
//sets the format of the textfield
onEnterFrame = function () {
textfield._alpha -= 5;
};

Thats all, its pretty simple.
I hope this tutorial helped.

freechips1
freechips1
  • Member since: Oct. 28, 2005
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Text Fadeout 2007-04-17 15:27:06 Reply

Thanks for that, this really helped cause I've been trying to do that for ages and I couldn't work out why it didn't work, so thanks again


Graagh? || Ich habe ein gros Hosenschlange

BBS Signature
noob-toast
noob-toast
  • Member since: May. 18, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Text Fadeout 2007-04-17 15:31:32 Reply

Nice simple effect. I've done a few studies and experiments with text in Flash, but I never really thought about _alpha. I never fade out text, because fading too many things out at once gets laggy, so I just fade the screen to a single color. Haha (:


These new signatures can suck on mah balls. My lolis don't fit in. Lol wut what are you guys still doing on NG, move on.

BBS Signature
EglStrk
EglStrk
  • Member since: Feb. 20, 2007
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to AS: Text Fadeout 2007-04-17 16:44:28 Reply

Actually, LesPaulPlayer, what you did is still inaccurate. If you increment or decrement the _alpha property directly you get inaccurate results. This is because Flash converts a value from 0% to 100% to an integer to between 0 and 255. A better way would be to increment a variable and then assign the _alpha property to that variable. In the example your showing this won't matter that much, but it's good to keep in mind when you're dealing with the _alpha property. Also, if the _alpha value of something is a fraction below 100%, set it to 100% or else Flash won't run as fast.


~There is never a good excuse for doing nothing. God grants liberty to those willing to stand for it!

LesPaulPlayer
LesPaulPlayer
  • Member since: May. 18, 2006
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Text Fadeout 2007-04-17 16:47:33 Reply

At 4/17/07 04:44 PM, EglStrk wrote: Actually, LesPaulPlayer, what you did is still inaccurate. If you increment or decrement the _alpha property directly you get inaccurate results. This is because Flash converts a value from 0% to 100% to an integer to between 0 and 255. A better way would be to increment a variable and then assign the _alpha property to that variable. In the example your showing this won't matter that much, but it's good to keep in mind when you're dealing with the _alpha property. Also, if the _alpha value of something is a fraction below 100%, set it to 100% or else Flash won't run as fast.

while interesting, none of that is actually relevant to the tutorial. Without the embedded fonts, there is no step between 100% and 0%, or 255 and 0. What you said is just general help for _alpha. Anyways, this code isnt meant to be copied straight into a game, I expect people to tweek it to there needs.

VariousX1
VariousX1
  • Member since: Nov. 23, 2006
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to AS: Text Fadeout 2007-04-22 18:42:09 Reply

Fantastic, thanks very much!

Claxor
Claxor
  • Member since: Oct. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Text Fadeout 2007-04-22 18:52:29 Reply

At 4/17/07 04:44 PM, EglStrk wrote: 0% to 100% to an integer to between 0 and 255

Flash Hacks w00t.


BBS Signature