一、样式、皮肤相关
1. 自定义ToolTip,详见 Flex/AIR个性化——ToolTip
2. 自定义ProgressBar样式,详见 Flex/AIR个性化——ProgressBar
二、其他
1. 读取资源文件中的项值:
1) 不带占位符的资源项:
<mx:Label text="{resourceManager.getString('common ', 'app.name' ) }"/>
common 为该资源文件名称(不包括后缀名properties),app.name 为其中的项的名称。
2) 带占位符的资源项:
若资源项 message. range =范围从{0}到{1} ,则可通过如下方式读取,a 将替换 { 0} ,b 将替换 {1}
resourceManager.getString("common ", "message.range ", [ a, b ])
2. 加载图片的几种方式:http://coffeelover.iteye.com/blog/891894
3. 图片的拉伸方法:(九宫格原理)

拉伸对应的代码为:
<mx:Image width="200" height="200" source="@Embed(source='/assets/tsj.jpg', scaleGridTop='1', scaleGridBottom='2', scaleGridLeft='1', scaleGridRight='3')"/>
4. data model 对象中的关联属性问题:
当被关联属性改变时,其他关联属性并不会自动进行相应更新,需要在被关联属性的set方法中增加如下处理:
var ce:PropertyChangeEvent =
PropertyChangeEvent.createUpdateEvent(this, propertyName, oldValue, newValue);
dispatchEvent(ce);
5. 将 <s:ButtonBar> 中的button宽度设为相同:
设置其 layout 的 variableColumnWidth 属性为 false,如:
<s:layout> <s:HorizontalLayout variableColumnWidth="false" /> </s:layout>
6. ButtonBar
1) 要对 ButtonBar 的某个button 的click 进行特殊处理时,可通过捕获 changing 事件,然后阻止默认来实现,如:
private function buttonbar_changingHandler(event:IndexChangeEvent):void
{
if (event.newIndex == event.target.dataProvider.length - 1) // last button
{
event.preventDefault();
// do something
}
}
2) requireSelection="false" 的 ButtonBar 清除按钮选中状态:以 ButtonBar 的click处理函数为例:
function buttonBar_clickHandler(event:MouseEvent):void
{
// 2个语句缺一不可
ButtonBar(event.currentTarget).selectedIndex = -1;
ButtonBarButton(event.target).selected = false;
}
7. 设置 spark FormItem 的 label 的水平对齐方式为 右对齐(与mx的form组件不同,需通过样式进行设置):
s|Form s|FormItem #labelDisplay {
textAlign: right;
}
8. 设置模态弹出窗口的背景色等,通过样式进行设置:
global {
modalTransparencyBlur: 0;
modalTransparency: 0.5;
modalTransparencyColor: grey;
modalTransparencyDuration: 500;
}
9. 用Path画一个向下的小三角:
<s:Graphic width="12" height="8"> <s:Path data="L 8 0 L 4 6 L 0 0"> <s:fill> <s:SolidColor color="0x000000"/> </s:fill> </s:Path> </s:Graphic>
10. mobile应用中,打开或关闭view menu:
FlexGlobals.topLevelApplication.viewMenuOpen = true; // true for open
11. AIR应用开机自启动(Windows/Linux平台下已测试,it works):
if (!Capabilities.isDebugger)
{
try
{
NativeApplication.nativeApplication.startAtLogin = true;
}
catch (error:Error)
{
// log
}
}
注:1) 如果在 debug 模式下运行,将抛出:Error #2014: Feature is not available at this time.
2) 绿色方式运行时,也会有 Error #2014.
本文总结了Flex开发中的多项实用技巧,包括自定义组件样式、资源文件读取、图片加载及拉伸方法、数据模型关联更新机制、ButtonBar按钮宽度统一设置等。此外还介绍了模态窗口样式设置、使用Path绘制图形、移动端视图菜单操作、AIR应用开机自启动配置等内容。
995

被折叠的 条评论
为什么被折叠?



