| 1 |
package { |
|---|
| 2 |
import flash.display.*; |
|---|
| 3 |
import flash.text.TextField; |
|---|
| 4 |
import flash.text.StyleSheet; |
|---|
| 5 |
import flash.events.Event; |
|---|
| 6 |
import flash.filters.GlowFilter; |
|---|
| 7 |
import com.nitoyon.as3query.*; |
|---|
| 8 |
|
|---|
| 9 |
// import shapes and force them to be linked in the SWF file. |
|---|
| 10 |
import test.Circle; Circle; |
|---|
| 11 |
import test.Rect; Rect; |
|---|
| 12 |
import test.RoundRect; RoundRect; |
|---|
| 13 |
import test.Polygon; Polygon; |
|---|
| 14 |
import test.Star; Star; |
|---|
| 15 |
|
|---|
| 16 |
[SWF(width="420", height="430")] |
|---|
| 17 |
public class CssSelectorDemo extends Sprite { |
|---|
| 18 |
// constructor |
|---|
| 19 |
public function CssSelectorDemo() { |
|---|
| 20 |
$(stage).attr({scaleMode: "noScale", align: "TL"}); |
|---|
| 21 |
|
|---|
| 22 |
// construct children by XML |
|---|
| 23 |
$(xml).appendTo(this); |
|---|
| 24 |
|
|---|
| 25 |
// construct CSS Test List |
|---|
| 26 |
as3Query.each(cssTest, function(i:int, css:String):void { |
|---|
| 27 |
$(TextField) // $(ClassName) equals $(new ClassName()) |
|---|
| 28 |
.css("p", { // set CSS |
|---|
| 29 |
fontFamily: "sans-serif" |
|---|
| 30 |
}) |
|---|
| 31 |
.attr({ // set the attributes |
|---|
| 32 |
text: "<p>" + css + "</p>", |
|---|
| 33 |
width: Number($("#ex").attr("width")) - 2, |
|---|
| 34 |
height: 19, |
|---|
| 35 |
x: 1, |
|---|
| 36 |
y: i * 20 + 1, |
|---|
| 37 |
selectable: false, |
|---|
| 38 |
backgroundColor: 0xaaaaff |
|---|
| 39 |
}) |
|---|
| 40 |
.hover( // hover event (over and out) |
|---|
| 41 |
function(event:Event):void { |
|---|
| 42 |
this.background = true; |
|---|
| 43 |
}, |
|---|
| 44 |
function(event:Event):void { |
|---|
| 45 |
this.background = false; |
|---|
| 46 |
} |
|---|
| 47 |
) |
|---|
| 48 |
.click( // click event |
|---|
| 49 |
function(event:Event):void { |
|---|
| 50 |
$("#q").text(this.text); |
|---|
| 51 |
changeHandler(null); |
|---|
| 52 |
} |
|---|
| 53 |
) |
|---|
| 54 |
.appendTo($("#ex")); |
|---|
| 55 |
}); |
|---|
| 56 |
|
|---|
| 57 |
// match filter |
|---|
| 58 |
$("TextField").bind("change", changeHandler); |
|---|
| 59 |
changeHandler(null); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
// TextField change handler |
|---|
| 63 |
private function changeHandler(event:Event):void { |
|---|
| 64 |
var f:GlowFilter = new GlowFilter(); |
|---|
| 65 |
$("*").attr("filters", []); |
|---|
| 66 |
$($("#q").text()).not(":root").attr("filters", [f]); |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
// CSS Test List |
|---|
| 70 |
private var cssTest:Array = [ |
|---|
| 71 |
"RoundRect", "Star[corner = 5]", "TextField[text $= t]", |
|---|
| 72 |
"Rect", "Rect:empty", "Rect:parent", |
|---|
| 73 |
"Rect Rect", "Rect * Rect", "Rect > Rect", "Rect + *", "Rect ~ *", |
|---|
| 74 |
"Circle", "Circle:nth-child(3)", "Circle:last-child", |
|---|
| 75 |
"Circle:nth(1)", "Circle:first", "Circle:even" |
|---|
| 76 |
]; |
|---|
| 77 |
|
|---|
| 78 |
// An XML that markups the positions and properties of shapes and TextField. |
|---|
| 79 |
private var xml:XML = |
|---|
| 80 |
<test.Rect width="400" height="410" x="10" y="10"> |
|---|
| 81 |
<!--input space--> |
|---|
| 82 |
<flash.text.TextField |
|---|
| 83 |
text="Type CSS Selector:" |
|---|
| 84 |
x="10" y="10" width="100" height="20" selectable="false"/> |
|---|
| 85 |
|
|---|
| 86 |
<flash.text.TextField |
|---|
| 87 |
id="q" type="input" |
|---|
| 88 |
text="RoundRect" |
|---|
| 89 |
x="120" y="10" width="270" height="20" border="true"/> |
|---|
| 90 |
|
|---|
| 91 |
<!--shapes--> |
|---|
| 92 |
<test.Rect x="20" y="50" width="100" height="100" color="0xcccccc"> |
|---|
| 93 |
<test.Star x="10" y="10" width="30" height="30" color="0xccffcc" corner="12" ratio="0.8"/> |
|---|
| 94 |
<test.Rect x="60" y="10" width="30" height="30" color="0xcceedd"/> |
|---|
| 95 |
<test.Circle x="10" y="60" width="30" height="30" color="0xccddee"/> |
|---|
| 96 |
<test.Rect x="60" y="60" width="30" height="30" color="0xccccff"/> |
|---|
| 97 |
</test.Rect> |
|---|
| 98 |
<test.RoundRect x="140" y="50" ellipseWidth="20" ellipseHeight="20" width="100" height="100" color="0xcccccc"> |
|---|
| 99 |
<test.Rect x="10" y="10" width="30" height="30" color="0xffcccc"/> |
|---|
| 100 |
<test.Polygon x="60" y="10" width="30" height="30" color="0xeeddcc" corner="3"/> |
|---|
| 101 |
<test.Rect x="10" y="60" width="30" height="30" color="0xccffcc"/> |
|---|
| 102 |
<test.Circle x="60" y="60" width="30" height="30" color="0xddeecc"/> |
|---|
| 103 |
</test.RoundRect> |
|---|
| 104 |
<test.Rect x="20" y="170" width="100" height="100" color="0xcccccc"> |
|---|
| 105 |
<test.Star x="10" y="10" width="30" height="30" color="0xccffcc"/> |
|---|
| 106 |
<test.Rect x="60" y="10" width="30" height="30" color="0xcceedd"/> |
|---|
| 107 |
<test.Circle x="10" y="60" width="30" height="30" color="0xccddee"/> |
|---|
| 108 |
<test.Rect x="60" y="60" width="30" height="30" color="0xccccff"/> |
|---|
| 109 |
</test.Rect> |
|---|
| 110 |
<test.Rect x="140" y="170" width="100" height="100" color="0xcccccc"> |
|---|
| 111 |
<test.Rect x="10" y="10" width="30" height="30" color="0xccffcc"/> |
|---|
| 112 |
<test.Star x="60" y="10" width="30" height="30" color="0xffeeee" corner="6" ratio="0.7"/> |
|---|
| 113 |
<test.Rect x="10" y="60" width="30" height="30" color="0xffccdd"/> |
|---|
| 114 |
<test.Polygon x="60" y="60" width="30" height="30" color="0xffccff" corner="5"/> |
|---|
| 115 |
</test.Rect> |
|---|
| 116 |
<test.RoundRect x="20" y="290" ellipseWidth="20" ellipseHeight="20" width="100" height="100" color="0xcccccc"> |
|---|
| 117 |
<test.Rect x="10" y="10" width="30" height="30" color="0xffcccc"/> |
|---|
| 118 |
<test.Polygon x="60" y="10" width="30" height="30" color="0xeeddcc" corner="3"/> |
|---|
| 119 |
<test.Rect x="10" y="60" width="30" height="30" color="0xccffcc"/> |
|---|
| 120 |
<test.Circle x="60" y="60" width="30" height="30" color="0xddeecc"/> |
|---|
| 121 |
</test.RoundRect> |
|---|
| 122 |
<test.RoundRect x="140" y="290" ellipseWidth="20" ellipseHeight="20" width="100" height="100" color="0xcccccc"> |
|---|
| 123 |
<test.Circle x="10" y="10" width="30" height="30" color="0xccffcc"/> |
|---|
| 124 |
<test.Circle x="60" y="10" width="30" height="30" color="0xffeeee"/> |
|---|
| 125 |
<test.Circle x="10" y="60" width="30" height="30" color="0xffccdd"/> |
|---|
| 126 |
<test.Circle x="60" y="60" width="30" height="30" color="0xffccff"/> |
|---|
| 127 |
</test.RoundRect> |
|---|
| 128 |
|
|---|
| 129 |
<!--examples--> |
|---|
| 130 |
<test.Rect |
|---|
| 131 |
id="ex" |
|---|
| 132 |
x="270" y="50" width="120" height="340" color="0xeeeeff"/> |
|---|
| 133 |
</test.Rect>; |
|---|
| 134 |
} |
|---|
| 135 |
} |
|---|