Archive for April, 2009
The enterFrame handler
Posted by Admin in Uncategorized on April 30th, 2009
The enterFrame handler takes the first 50 characters from tickerText and places them in text. The first 50 characters will be spaces because we placed them there at the end of the load handler.
Then, firstChar is moved over by one. In the next frame, instead of characters 0 through 49 being displayed, characters 1 through 50 will. Then 2 through 51. This is how the text appears to scroll.
The enterFrame handler also tests firstChar to see whether it is beyond the end of the string length. If it is, it sets firstChar back to 0, so the whole thing starts over again.
onClipEvent(enterFrame) {
// set the text to this segment
text = tickerText.substr(firstChar,lineLength);
// move segment by one character
firstChar++;
// if all text used, then start over again
if (firstChar > tickerText.length) {
firstChar = 0;
}
}
Using the movie you created, or the example movie 10ticker.fla, try changing the text in tickerText and the lineLength to see the effect.
This example would be a good place to use external text rather than hard-coded text. You can use either the HTML or external text file technique to read in text from an external source to populate tickerText.
Note that this might take some adjustment because you need to remember that the tickerText variable is in the movie clip, not the root level. So if you define a variable in the URL, or you load one using loadVariables at the root level, you will need to refer to _root.tickerText rather than tickerText.
Although this example is a great way to learn dynamic text field and string functionality, it is not the best way to create a ticker effect. Instead, you can create a wide dynamic text field, mask its left and right sides, and have it slide slowly to the left. This creates a smoother ticker and allows you to use non-monospaced fonts.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Adjust the font to use a monospaced font
Posted by Admin in Uncategorized on April 29th, 2009
Adjust the font to use a monospaced font, such as Courier New.
Select the text area and choose Insert, Convert To Symbol. Choose Movie Clip as the type of symbol and name it anything you want. The text field is now the only component of a movie clip.
Using monospaced fonts is an important part of many text effects. Monospaced fonts are different from normal fonts in that each character is the exact same width. This makes it easier to predict the width of text lines and to line up columns of text. Examples of monospaced fonts are Courier New and Monaco.
The script attached to the movie clip starts by initializing a variable called tickerText that will hold the complete text to be displayed. The script also initializes firstChar to 0, which will be the first character displayed in the text field, and lineLength to 50, which will be the number of characters displayed at one time.
Then, the handler places a number of spaces at the start of tickerText. This is to make the text start with all spaces and then gradually come in from the right.
onClipEvent(load) {
// full text
tickerText = “News Alert: “;
tickerText += “Stock prices shoot up sharply with good earnings reports. “;
tickerText += “The first manned flight to Mars prepares to leave Earth orbit. “;
tickerText += “Your favorite sports team wins championship. “;
tickerText += “Scientists find cure for major diseases. “;
firstChar = 0; // start at character 0
lineLength = 50; // show this many characters
// put spaces before text
for(var i=0;i
}
}
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
If you run the movie
Posted by Admin in Uncategorized on April 28th, 2009
If you run the movie, the text in the dynamic field textField is replaced with text from the text file. Here are the contents of the text file:
textField=Weather today:
Sunny, with a high of 72.
Chance of showers tonight.
An external text file works the same as the extra information in the HTML tag. You can define as many variables as you want, separated by &. Line breaks don’t matter, which is why all three lines of text get assigned to the textField variable.
Task: News Ticker
A simple example that we can build using string functions and a dynamic text member is a scrolling text ticker. This looks like the old-fashioned news tickers that appeared on the sides of buildings announcing news and stock prices.
The idea is to have one line of text, which gradually scrolls to the left, revealing more characters to the right while characters disappear from the left.
Start with a blank movie.
Create a dynamic text field that is only one line high but stretches the entire width of the work area. You can place anything in the text field, such as “Text goes here.”
Link this text field to the variable text.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
You can set more than one variable
Posted by Admin in Uncategorized on April 27th, 2009
You can set more than one variable by placing a & character after each variable declaration and then starting a new declaration. Here is an example:
Variables from External Files
You can also get variables from an external text file. Why would you want to do this? Well, suppose that you make a movie that displays some dynamic information, such as a weather report. You can make the movie once and then change a text file on the server to update the text. Someone who doesn’t even use Flash can then update the contents of the movie.
To do this, you’ll need a single command inside the Flash movie. The file 10external.fla has an example. It loads the variables from the file 10external.txt.
loadVariables (”10external.txt”,_root);
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
To get some text
Posted by Admin in Uncategorized on April 26th, 2009
To get some text, or any variable value, from the HTML page, you need to add it to the movie source tags in the HTML. So, first, publish your movie. Then, open the HTML page created. You’ll see the combination OBJECT/EMBED tag there.
The OBJECT tag defines the Flash movie for the Internet Explorer browser on Windows machines. The EMBED tag defines it for other browsers, so you’ll have to make the change in two places. For instance, if you want to set the variable textField, you need to do this in the OBJECT tag:
Then, later in the EMBED tag, you need to make a similar change:
src=”10banner.swf?textField=Text from HTML!”
Check out the file 10banner.html in a text editor such as SimpleText or WordPad to see exactly where the changes go.
The result is that when the movie loads, the variable is created and set to this value. Check the movie 10banner.fla to see a movie that is set up to use this type of thing. Drag and drop the 10banner.html file onto your favorite browser to see what happens.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
You can see this code
Posted by Admin in Uncategorized on April 25th, 2009
You can see this code in action in the example movie 10formattext.fla. The setTextFormat command can also accept a second and third parameter to tell it the first and last characters to apply the format to.
You can use text format objects like style sheets in HTML. You can define several of them at the start of your movie and then apply those formats as you need them throughout the movie.
External Variables
Flash allows you to bring external text into a movie by using ActionScript. You can put the external text in the HTML page or in a completely separate file.
Variables from the HTML Page
You can define the initial value of a variable in the HTML page where the Flash movie is embedded. Why would you want to do this? Well, consider an example like a Flash banner that appears on top of a Web page. Instead of making 30 banners for 30 Web pages, you could make one banner and have the different text in the HTML of each page so that the banner displays a different title on each page. One Flash movie works for all 30 pages.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
TextFormat Object
Posted by Admin in Uncategorized on April 24th, 2009
Another way to set the font, size, and style of dynamic text is to use a TextFormat object. To do this, you create a variable and define it as an instance of TextFormat. Then, you can set various properties of this variable. In this example, the font is set to Arial Black, the size is set to 26, and the color is set to red. The dynamic text field has been named textInstance. We have never named a text field before, but you can see in Figure 10.1 where the name goes.
myFormat = new TextFormat();
myFormat.font = “Arial Black”;
myFormat.size = 36;
myFormat.color = 0xFF0000;
textInstance.setTextFormat(myFormat);
You have to use various methods in Flash to define colors. It depends on what part of ActionScript you are using at the time. In this example, 0xFF0000 is used, where the initial 0x defines this as a hexadecimal color definition. However, in the earlier HTML tag, we used #FF0000 to define the same color.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Notice that it is not a complete
Posted by Admin in Uncategorized on April 23rd, 2009
Notice that it is not a complete HTML page with a
tag or anything, so it is not true HTML. However, by using regular tags such as , , and , it is easy to learn and remember what works. Here is a complete list of tags that work in Flash 6:: Bold
: Italics
: Underline
: Font
: Set text size
: Hypertext link to a Web page
: Define a paragraph
: New line
The hyperlink is the most functional of all the tags. On the one hand, it doesn’t display blue and underlined like tags do in browsers, but it does work the same. If you click on a link, the page it refers to will load. If you want to color or style the text, you can apply those tags independently of the tag.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
The Character button in the Properties
Posted by Admin in Uncategorized on April 22nd, 2009
The Character button in the Properties panel lets you decide which characters of the font will be saved with the movie when you publish it.
Say that you have a dynamic text field and you want to put “Hello World.” into it. First, you need to set the Var property in the panel to a variable name, such as myText. After that is done, don’t worry about the field, just set the variable.
myText = “Hello World.”;
It’s that easy. But you can do much more with dynamic text fields.
HTML Formatting
The easiest way to add formatting to dynamic text fields is to use HTML. First, you’ll need to set the field to accept HTML. You do this by clicking the little Render Text as HTML button in the middle of the Properties panel. It looks like a “<>“. When this is turned on, you can use a few select tags to change your text. Here is an example:
myText = “This text is bold.
“;
myText += “This text is italic.
“;
myText += “This text is underlined.
“;
myText += “This text is red.
“;
myText += “This text is Arial Black.
“;
myText += “This text is large.
“;
myText += “This text is linked.
“;
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours
Although you can change
Posted by Admin in Uncategorized on April 21st, 2009
Although you can change the x and y position of the field in the Properties panel, don’t change the width and height. Doing so does not make the text area larger, but instead stretches any text inside it. If you want to change the width and height of a dynamic text field, do so by grabbing the bottom-right corner of the field in the work area and dragging.
In the middle of the Properties panel, you will see three little buttons. The first, which looks like an “Ab” lets you decide whether the user can select the text in the field.
Select this option if the user is supposed to be allowed to select and copy the text. In most cases, you will want it off. The next little button determines whether you can use HTML formatting in the field. We’ll look at HTML formatting in the next section. The third button places a border around the field.
Taken From: Sams Teach Yourself Flash™ MX ActionScript in 24 Hours


Recent Comments