Format Flash text with CSS

Source: Internet
Author: User
Tags format define html tags modify string
A new feature of CSS flashMX2004 is the ability to load external CSS files and apply them to flash text, and now there is a new class (class?). Because the new ActionScript2 is a class-based scripting language: Textfield.stylesheet class, several ways of this class enable us to format flash text like HTML definition CSS, such as font size, color, location, and so on. Later we want to change the style of the flash text just modify the external CSS file without having to modify it in the FLA file.
Before you start, you need to make sure that you have flashMX2004 and knowledge of HTML, which should be basically done, ok~ ready ... Start ~

First create a new CSS file, you can use DWMX2004 or other text editing tools:. texttitle {
Font-family:verdana, Arial, Helvetica, Sans-serif;
font-size:12px;
Font-weight:bold;
Color: #993300;
Text-align:center;
}
. textcontent {
Font-family:arial, Helvetica, Sans-serif;
font-size:12px;
Color: #000000;
}

Save the file and name it externalcss.css, then create a new Flash document, drag (or double-click) a textarea component from the components panel to the scene,



and name the component "MyText":



The textarea component's height and width are determined by how much text you have, and make sure that its HTML parameter is true:

Next, we'll write as, select the first frame of the timeline, press the shortcut key "F9", and eject the action panel:

New Style Sheet Object
var mycss = new Textfield.stylesheet ();
CSS file location
var cssurl = "Externalcss.css";
Define the contents of the text box component, this is with you.
var textstr:string = "<p class= ' texttitle ' > Xu Wei--One day </p>
<span class= ' textcontent ' >
In the morning till the night the world keeps spinning and the winter is far away and the spring brings endless warmth
I'm standing here quietly feeling and you through the years of wind
</span> ";

Load an external CSS file and determine if the load succeeded
Mycss.load (Cssurl);
Mycss.onload = function (suc) {
if (suc) {
If the load succeeds, set the text box content and apply the CSS that is loaded in
Mytext.stylesheet = Mycss;
Mytext.text = Textstr;
}
};

The above paragraph as I will no longer explain, the annotation inside is very clear, need to explain is to define text string of time to use two HTML tags:<p> and <span>, the function is to define CSS for flash text, That's why I mentioned earlier about the need for a bit of HTML knowledge. OK, save the Flash directory to the Externalcss.css file, Ctrl+enter, is the text effect as defined in the CSS file? Oh, so simple.


You can also use the SetStyle () method of Textfield.stylesheet class to create CSS, or take the above example:

 var mycss= new Textfield.stylesheet (); 
Mycss.setstyle ("Texttitle",
    {font-family: ' Verdana, Arial, Helvetica, Sans-serif ',
      font-size: ' 12px ',
      font-weight: ' Bold ',
       color: ' #993300 ',
      text-align: ' Center '}
;
Mycss.setstyle ("Textcontent",
    { font-family: ' Arial, Helvetica, Sans-serif ',
      font-size: ' 12px ',
      color: ' #000000 '}
);
var textstr:string = "<p class= ' texttitle ' > Xu Wei--one day </p>
    <span class= ' Textcontent '
     morning to night the world keeps spinning cold winter has gone far spring brings endless warmth
    I stand here quietly feeling and you through the years Gusts of wind
    over my body it wakes me up and I wake up to all the sadness and joy all melted into the splendid sunset </span> ";
Mytext.stylesheet = Mycss;
Mytext.text = textstr; The

code has the same effect as loading an external CSS file above.
Photo: [Flash-supported CSS1.0 property value]


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.