1、在flex,if语句可以直接判断一个对象是否是null,而不需要像java中那样必须用obj==null的形式,代码如下
if (obj) {
//expression
}
2、string对象未初始化的时候是null
3、根据命名空间后面第一个字母的大小写可以判断使用的是类的实例还是属性。具体为:如果第一个字母是大写的比如<S:Button>,就说明代码引用的是一个类的新实例,如果第一个字母是小写的比如<s:label>,就说明是在设置一个类的属性。
2012-5-28
4、将currentState设为空字符串(this.currentState=''),能将应用程序重置为初始状态。
<s:Button label="View Cart" click="this.currentState='cartView'" includeIn="State1"/>
includeIn,将组件包含在某种state中,即在该state时,显示此组件
5、开发一个不访问因特网的离线应用程序,可以使用@Embed指令来在生成的swf文件中包含Image控件。这种机制与运行时加载图片相比有两个优势:第一,图片在应用程序开始时就已经加载,因此用户不需等待图片显示。第二,无需访问网络,可以直接使用。但是使用这种技术会显著增加swf文件的大小。
<mx:Image scaleContent="true" source="@Embed('assets/dairy_milk.jpg')"/>
Flex 可以设置图片的宽度和高度,并缩放图片以使其符合Image控件的大小。
6、<s:RichText>组件可以显示多行文本。
7、<s:Button y="10" label="View Cart" id="btnCartView" right="90" click.State1="this.currentState='cartView'"/>
当currentState为State1 的时候click事件才有效。
8、<fx:Declarations> 和<fx:Model>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<fx:Model id="groceryInventory">
<groceries>
<catName>Dairy</catName>
<prodName>Milk</prodName>
<imageName>assets/dairy_milk.jpg</imageName>
<cost>1.20</cost>
<listPrice>1.99</listPrice>
<isOrganic>true</isOrganic>
<isLowFat>true</isLowFat>
<description>Direct from California where cows are happiest!</description>
</groceries>
</fx:Model>
</fx:Declarations>
引用model里的数据 <s:RichText text="{groceryInventory.description}" width="50%"/>
2012-05-31
1、访问首页中的数据
FlexGlobals.topLevelApplication.defaultProjectId
2012-6-12
1、通过 borderWeight="0" 设置BorderContainer的边框粗细。
<s:BorderContainer borderWeight="0"></s:BorderContainer>
2、通过HGroup设置水平布局
<s:HGroup>
<s:Button width="72" height="26" label="Login"/>
<s:Button width="72" height="26" label="Cancel"/>
</s:HGroup>
那么这个类的属性如果发生了变化,则会触发绑定。
// 得到字符串的真实长度(双字节换算为两个单字节)
private function getStrActualLen(sChars:String):int
{
return sChars.replace(/[^\x00-\xff]/g,"xx").length;
}
//中文按2个字符计算
if( getStrActualLen(this.v0.text)>100)
{
Alert.show("最多输入"+(100)+"个字节,1个中文为2个字节。","提示:");
this.focusManager.setFocus(this.v0);
return;
}
/[^\x00-\xff]/g 是正则表达式,代表汉字
<s:states>
<s:State name="state1"/>
<s:State name="state2"/>
</s:states>
通过states设置视图状态,其中第一个状态为默认状态
cornerRadius="8"
2012-8-9
<mx:itemRenderer>
<fx:Component>
<mx:LinkButton label="{data.label}" textAlign="left" paddingLeft="2"
icon="{data.icon}"
click="{outerDocument.onClick(data.id);}"/>
</fx:Component>
</mx:itemRenderer>
2012-8-15