Adding Line Breaks to Flash Checkboxes & Radio Buttons
Posted by Anthony in Flash, Tutorials tagged actionscript 3, components, Flash
I was recently working on a Flash website where the space in the registration form was really tight. I needed to squeeze a full sentence into a checkbox label, but only had enough room for about half of the sentence to fit. I needed a line break in the checkbox label, but found that trying to add one in using the Component Inspector did nothing. So I went to ActionScript.
Using ActionScript 3.0, you can add labels to your CheckBox and RadioButton components, as long as they have a unique instance name. The simple syntax for doing this is:
myCheckBox.label = "Hello, World!";
If you need to add in a line break, all you need to do is include “\n” where you want the line break. Using the previous line of code as an example, we could break the two words into two lines by putting:
myCheckBox.label = "Hello, \nWorld!";
If you find it hard to read the string with the “\n” scrunched right up against a word, you can always concatenate strings together for greater code legibility. An example would be:
myCheckBox.label = "Hello," + "\n" + "World!";
The line of code above does the exact same thing, but shows you more cleanly where your line break is, should you need or want to see it better.
So there you have it. Line breaks in your Flash components using ActionScript 3.0. Until next time, happy coding!

Facebook
LinkedIn
Twitter
There are no comments yet, add one below.