flex小技巧综合
flex 小技巧
1. 将组件放到最上层
父容器.setChildIndex(你要的TitleWindow,父容器.numChildren- 1);
2.array的赋值:
1.可以长度不一致
2.可以变量
3.可以push空数组 push([])
e.g.
var aa:int = 1; var a:Array = [aa,2,3]; var b:Array = [2,3]; var c:Array = [1,2,3,4]; array.push(a); array.push(b); array.push(c); array.push([aa,aa,aa]); array.push([]);
3.禁止下拉框
verticalScrollPolicy="off" horizontalScrollPolicy="off"
4.变量的访问ArrayCollection中的值
ArrayCollection["name"]
5.画点
var circle :Sprite = new Sprite();var comp:UIComponent = new UIComponent();circle.graphics.beginFill(0xDC143C);circle.graphics.drawCircle(x,y,r);comp.addChild(circle);worldmap.addChild(comp);
6.画边界
var bounds:Sprite = new Sprite(); bounds.graphics.beginFill(0x000000); bounds.graphics.drawRect(x1,y1,w1,h1); bounds.graphics.drawRect(x2,y2,w2,h2); bounds.graphics.endFill(); var comp:UIComponent = new UIComponent(); comp.addChild(bounds); panel.addChild(comp);
7.arrayCollection排序
import mx.collections.SortField; import mx.collections.Sort; import mx.collections.ArrayCollection; private var acSort:ArrayCollection= new ArrayCollection([{id:0,userName:"zhangSan",age:21}, {id:2,userName:"liSi",age:24}, {id:1,userName:"wangWu",age:31}]); private function sortAc():ArrayCollection{ var sort:Sort=new Sort(); //按照ID升序排序 sort.fields=[new SortField("id")]; //按照userName降序排序 sort.fields=[new SortField("userName",true,true)]; //先按ID升序,再按userName降序 sort.fields[new SortField("id"),new SortField("userName",true,true)]; acSort.sort=sort; acSort.refresh();//更新 return acSort; }
7.设置Alert的字体样式
<mx:Style> Alert{ titleStyleName: "alertTitle"; messageStyleName: "alertMessage"; buttonStyleName: "alertButton"; cornerRadius: 10; embedFonts: true; } .alertTitle { letterSpacing: 0; fontSize: 14; color: red; } .alertMessage { letterSpacing: 2; fontSize: 14; fontWeight: bold; color: #000000; } .alertButton { letterSpacing: 0; fontSize: 12; fontWeight: normal; color: black; } </mx:Style>
8.读JSON串的键值
var obj:Object = JSON.decode(jsonString); for each(var key:String in obj){ trace("key:"+key+" value:"+obj[key]); }