To create a new TextArea which loads a text file, I am going to give you a method which worked for me. It requires three separate documents, which I will not type out in their entirety. I will just give you a sample.
1) Drag a TextArea Component from the component library onto your Flash stage and give it an instance name of myText in the Properties Inspector.
2) 2. In a text writer or Dreamweaver, Create a CSS file and name it sample.css. I started by using the Text Enhancement Tutorial provided by MM in Flash 2004. One thing that is important to note is that most of the styles use NON-HTML tags. The reason for that is that Flash does not interpret many standard tags. However, it seems to have no problem with CSS tags created from new words like headline or italicy. It is also important to use the display:block definition if you want paragraphs. Using display:block allows you to format your text without using excessive line breaks, which can cause problems. And if you want to change the color of your text, the CSS file is the best and easiest way to do that. Define your text colors here! Here is part of my sample.css:
headline
{
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
font-size: 16px;
font-weight: bold;
display: block;
}
mainBody {
font-family: Arial,Helvetica,sans-serif;
color: #FFFFFF;
font-size: 12px;
display: block;
}
italicy {
font-family: Arial,Helvetica,sans-serif;
color: #FFFFFF;
font-size: 12px;
font-style: italic;
display: inline;
}
biline {
font-family: Arial,Helvetica,sans-serif;
color: #FFFFFF;
font-size: 13px;
font-style: italic;
display: inline;
}
A {
font-family: Arial,Helvetica,sans-serif;
color: #cccccc;
font-size: 12px;
display: inline;
text-decoration:underline;
}
3) Create a text file with CSS defined tags, and place all your text on a single line. Save this file as loadtext.xml. At this point, you could create an HTML file instead, and it should not pose a problem. However, using the XML Class definition, an XML file just seems more consistent to me. Here is a sample of my XML text file:
<loadtext>
<headline>Digital Video and Sound</headline>
<mainBody>
<biline>Flash Streaming, QuickTime, RealVideo/Audio,
CD/DVD, Web Streaming, Animation/Voice, Original
Music</biline>
</mainBody>
<br>
<subheadline>Digital Video For Web Sites</subheadline>
<mainBody> Digital Video and Animation Services are
provided by Peterson Sales in cooperation with DVI
Studios… </mainBody>
</loadtext>
4) Finally, add the following code to a frame on the stage, and for safety's sake, make sure the component is visible on the stage in the same time frame as the code. (Some of these variables can be changed in the Property Inspector, but what is written on the stage overrides the Inspector's settings.)
// set properties for a TextArea component on the
// stage with instance name "myText"
myText.html = true;
// allows html tags and XML styles to be displayed
myText.wordWrap = true;
myText.multiline = true;
// makes it scrollable
loadtextStyle = new TextField.StyleSheet();
// create a new instance of a Class StyleSheet
loadtextStyle.load("sample.css");
// loads your CSS document with defined tags
myText.styleSheet = loadtextStyle;
// applies your new XML styles to myText
myText.setStyle("backgroundColor","0x000099");
// sets the background color
// (Text color is set in the CSS.)
loadtextContent = new XML();
// create a new instance of an XML Class
loadtextContent.ignoreWhite = true;
loadtextContent.load("loadtext.xml");
// identifies the file to be loaded
loadtextContent.onLoad = function(success)
{
if(success)
{
myText.text = loadtextContent;
// loads the file into the TextArea
}
}
There you have it. It is beyond the scope of this tutorial to explain the XML structure or the reasons behind the Class requirements for this component. I am learning as I go and awaiting some good third party books on ActionScript 2. But this procedure works and is given to get you started. I defy anyone to tell me that this is easier than adding text in Flash 5 or MX. It may be more controllable and more powerful, but there are many more steps involved. The one upside to this new structure is that once you have defined a style set, you can govern the appearance of your entire Flash site by changing just one file, and by loading the content file from a website, you can change the text, HTML, or XML file without opening Flash. But this complex situation for a basic need like text control is still 2 steps forward and 2 steps back.
I hope this little tutorial saves you from some of the frustration and pitfalls I experienced with this new version of Flash as we all await better documentation for the new features.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |