package { import flash.display.*; import flash.text.TextField; import flash.text.StyleSheet; import flash.events.Event; import flash.filters.GlowFilter; import com.nitoyon.as3query.*; // import shapes and force them to be linked in the SWF file. import test.Circle; Circle; import test.Rect; Rect; import test.RoundRect; RoundRect; import test.Polygon; Polygon; import test.Star; Star; [SWF(width="420", height="430")] public class CssSelectorDemo extends Sprite { // constructor public function CssSelectorDemo() { $(stage).attr({scaleMode: "noScale", align: "TL"}); // construct children by XML $(xml).appendTo(this); // construct CSS Test List as3Query.each(cssTest, function(i:int, css:String):void { $(TextField) // $(ClassName) equals $(new ClassName()) .css("p", { // set CSS fontFamily: "sans-serif" }) .attr({ // set the attributes text: "

" + css + "

", width: Number($("#ex").attr("width")) - 2, height: 19, x: 1, y: i * 20 + 1, selectable: false, backgroundColor: 0xaaaaff }) .hover( // hover event (over and out) function(event:Event):void { this.background = true; }, function(event:Event):void { this.background = false; } ) .click( // click event function(event:Event):void { $("#q").text(this.text); changeHandler(null); } ) .appendTo($("#ex")); }); // match filter $("TextField").bind("change", changeHandler); changeHandler(null); } // TextField change handler private function changeHandler(event:Event):void { var f:GlowFilter = new GlowFilter(); $("*").attr("filters", []); $($("#q").text()).not(":root").attr("filters", [f]); } // CSS Test List private var cssTest:Array = [ "RoundRect", "Star[corner = 5]", "TextField[text $= t]", "Rect", "Rect:empty", "Rect:parent", "Rect Rect", "Rect * Rect", "Rect > Rect", "Rect + *", "Rect ~ *", "Circle", "Circle:nth-child(3)", "Circle:last-child", "Circle:nth(1)", "Circle:first", "Circle:even" ]; // An XML that markups the positions and properties of shapes and TextField. private var xml:XML = ; } }