Using CSS (Cascading Style Sheets) in Action Script - Helper class (for TextField, Label Control, or other text control)

This is a helper class for using Cascading Style Sheets for the assignment of different properties with CSS.

import flash.text.*;
import fl.controls.* 

var ss:StyleSheet = new StyleSheet();
s.parseCSS(".lblStyle{ font-size:12;font-family: Arial;color:#000000; } .textFieldStyle{font-size:12;font-family: Arial;color:#FF0000;}")

var lbl:Label = new Label();
CssHelper.setStyle(lbl.textField, ss, ".lblStyle");

var tf:TextField = new TextField();
CssHelper.setStyle(tf, ss, ".textFieldStyle");

This is a sample CSS that you could store in an XML file:


This is one useful utility for tracing objects in ActionScript 3 code. The name of the class is just t (from tracer). I find that short name easier to type. If you have the interface mx.collections.IList you can download it from here or if you don't from here

So if you want to trace just a string you can use it as:

t.str("some string");

// the trace: 
// some string

or you can use multiple arguments:

t.str("some string", 15, true);

// the trace: 
// some string | 15 | true

or if you have an object defined for example like this one:


The lack of control over the background, border and focus indicator of ActionScript 3 TextArea control is quite annoying and here is the control, extension of the original TextArea that can be a solution of that problem. Create folder fl in your class path (class path can be defined at File - Publish Settings - Flash - Settings) then create folder controls inside of fl folder then create file and paste the following class.

Here is how you can use it: