- Create a Class file and name it CSSFormattingExample.as.
- Lets copy below code and paste it in "CSSFormattingExample.as".
- Create a new CSS file including below code and lets save it as "example.css" CSS File:
- Open a new FLA file and save it as "CSSFormattingExample.fla"
- Create a new movieclip name it "CSSFormattingExample".
- Select "Export for ActionScript" checkbox from movie clip properties panel.
- In Class textbox write class name as "CSSFormattingExample".
- Create a new text field in "CSSFormattingExample" movieclip and write instance name of text field as "txtField".
- Now create another new FLA file and save it as "fonts.fla".
- Create a new dynamic text field and select font as "Arial Rounded MT Bold".
- Click Embed button from Properties panel of text field and embed desired font outlines.
- Publish this file.
- Try publish your "CSSFormattingExample" FLA and you are done.
package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.net.URLLoader; import flash.net.URLRequest; import flash.text.StyleSheet; import flash.text.TextField; import flash.text.TextFieldAutoSize;
public class CSSFormattingExample extends MovieClip {
private var fontLoader:URLLoader; private var loader:URLLoader; private var field:TextField; private var exampleText:String = "<h1>This is a headline</h1>" + "<p>This is a line of text.</p> <span class=\"bluetext\">" + "This line of text is colored blue.</span>";
public function CSSFormattingExample():void {
fontLoader = new URLLoader(); fontLoader.addEventListener(Event.COMPLETE, onFontLoaded); fontLoader.load(new URLRequest("fonts.swf"));
}
public function onFontLoaded(event:Event):void {
field = txtField; field.width = 300; field.autoSize = TextFieldAutoSize.LEFT; field.wordWrap = true; var req:URLRequest = new URLRequest("example.css"); loader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onCSSFileLoaded); loader.load(req);
}
public function onCSSFileLoaded(event:Event):void { var sheet:StyleSheet = new StyleSheet(); sheet.parseCSS(loader.data); field.styleSheet = sheet; field.htmlText = exampleText; } } }
p {
font-family: Arial Rounded MT Bold;
font-size: 14;
}
h1 {
font-family: Arial Rounded MT Bold;
font-size: 30;
font-weight: bold;
}
.bluetext {
color: #0000CC;
font-size: 14;
}


0 comments:
Post a Comment