This is actually a very simple tutorial, but it took me a while to figure out because I couldn't find anything about it anywhere!
First things first, create a text box and set it anywhere on the screen. This is the only asset, so you don't need seperate layers (unless you want to keep the good habit going! You do need to name it, however. If you want to copy mine, I used the name "text". Make sure that it's set to dynamic text and the render text as html is selected (it looks like the <%lt%><%gt%> symbol, to the right of the selectable button and two left from the var: box). Without this box, all HTML code would simply appear as normal letters!
Next, open up the actions screen. This program is only four lines long; it could be one, but it's always important to make your code as easy to edit as possible! Let me explain each line here:
- word = "red";
- color = "\"#FFFF00\"";
- text.htmlText = "This is <%lt%>FONT COLOR="+color+"<%gt%>" +word+"<%lt%>/FONT<%gt%>.";
Line One: I created a variable simply called "word" and set it to "red". Make sure the quotes are there, or it'll try to take from a variable instead of using the text.
Line Two: Another variable - color. To render HTML colors, you need it in hexadecimal format: "#RRGGBB", quotes included. To create the quotes, use the \". That's why that looks so funky :)
Line Four: This is the code that actually does the work. First, to make it format using the html, you need to use the .htmlText instead of .text. Then, we get to <%lt%>FONT COLOR="+color+"<%gt%>". To simplify, this translates to <%lt%>FONT COLOR="#FFFF00"<%gt%>. If you've ever used HTML, you'll realize the similarities. Second, following this is +word+. This simply adds the word variable in there. Then you close the font tag (<%lt%>/FONT<%gt%>), and presto!
Now here comes the fun part: Go ahead and switch those variables up! As long as you keep the color one the same, with 6 letters/numbers 0-F, it'll work. If you want a specific color, just look online for hexadecimal color codes.
And, finally - if you still have any questions, don't hesitate to let me know!
|» Level Basic|
Rating: 5 Votes: 1
|Contract Game Developer, specialized in Flash. Still learning as I go (that's the fun!), and always glad to share what I learn.|
|Download the files used in this tutorial.|
|Download (20 kb)|
|More help? Search our boards for quick answers!|