1.不少组件有change事件,TabBar的change事件:
private function tabBarChangeHandler(event:Event):void{
var tabBarTager:TabBar=event.currentTarger as TabBar;//进行类型强制转换
//var tabBarTarget:TabBar=TabBar(event.currentTarget)这样也是可以的
var selectedIndex:int=tabBarTarget.selectedIndex;//得到索引值;
}
2.在caringrom框架里面的command执行方法里面委托类对象会被创建,做业务方法调用,例如var delegate:AuditServiceDelegate = new AuditServiceDelegate(this);
var eventData:Object=event.data;
delegate.getAuditList(eventData.pageIndex, eventData.perPage, eventData.appType, "pass", "second", "", "", eventData.appName);
之前懵懵懂懂,不知道应该用在什么地方。
3.分页。创建vo类PageBean,在view组件里面应该创建对象,利用LinkBean进行导航,enabled属性判断是否有效。使用comboBox进行具体页选择,close时候触发事件,返回分页对象给数据层,更新数据显示。
4.如何使用Title弹出module。我们应该有一个TitleWindow组件,同时在上面写好ModuleLoader,给它一个ID,再写一个loadModule(url:String)方法,加载的时候传进来一个url就可以了。最后我们当然还是需要PopUpManager来弹。
5.利用DataGrid展示数据需要使用到“dataField=“@*”来指定字段。
6.使用ExternalInterface和其静态方法call可以用来和js交互,调用其方法。
7.使用TitleWindow的defaultButton属性可以指定默认的button。
8.上网搜索不到关于列表多选的,自己摸索了一下,以TileList为例子:必须首先设置属性allowMultipleSelection为true才可以按住ctrl(上网不知道哪个混蛋乱叫说要加上shift)多选;接着调用它的方法selectedItems,该方法返回值类型为Array。因此,进行转型是必要的。
9.关于列表组件,单一显示字段可用labelField即可,显示多字段文字可以使用labelFunction,注意回调函数的参数为Object,返回值为String;当满足不了需要的时候可以使用ItemRenderer外部渲染器进行渲染,它可以显示图片文字等等。
10.为DataGridColumn添加内联的编辑控件:将editable属性设置为true,再通过itemEditor和editorDataField(其值为value)指定数据编辑器即可。下面是内置的控件:Button,label,NumbericStepper,DateField,image,checkBox,ComboBox,text(默认),textArea,TextInput
11.怎么写DataGrid的回调函数:private function labelRenderer(item:Object,dataField:DataGrid):String{}
12.观察客户端和服务器端的数据交换。处理服务器端数据交互时产生的调试任务往往最让人头疼,有时候无法搞清楚问题的出现是因为客户端收到数据以后处理有误还是没有收到预期数据。<mx:TraceTarget/>标签可以提供客户端与服务器端之间通信的大量信息。
13.牢牢记住Object是个动态类,当你要传递多个值的时候显得特别有用。某天当你的老板要你在事件当中传递数据,数据当中包括了一个数组和字符串,这个时候你就会发现Object类是多么有用了。var dataObj:Object=new Object();
dataObj["weatherContent"]=this.weatherContent.text;dataObj["list"]=weatherinfoArrayCollection;
CairngormUtil.dispatchEvent(AppEventNames.ADD_WEATHER,dataObj);
14.ObjectHandles这个是一个不错的开源工程,可以让你动态拖拽组件的位置,改变大小。
15.最后提醒一下自己,从服务器上面checkOut下来的代码要先build一下。
16.创建新窗体的函数代码如下:public function createWindow(object:DisplayObject):Object{
var documentItem:DisplayObject=this.documentWindow.addChild(object);
this.documentWindow.selectedIndex=this.documentWindow.numChildren-1;
return documentItem;
}其中,documentWindow是某个导航容器。调用代码如下private function divisionManageAction():void{
var division:Division=new Division();
this.createWindow(division);
}
//关闭所有窗口函数的具体实现
private function closeAllWin():void{
documentWindow.removeAllChildren();
}
17.xmllist充当数据源,从服务器端传回来了xml字符串怎么转换成为xmllist。
public function result(data:Object):void
{
var menuXmlString:String=data.result as String;
menuModelLocator.myMenu.menuData=new XML(menuXmlString).children();
//TODO: implement function
}
18.如何关闭当前IE浏览器<mx:Button textAlign="center"
label="Close current IE"
click="navigateToURL(new URLRequest('javascript:window.opener=null;window.close()'),'_self')"/>
19.切换全屏,按钮触发函数如下:public function toogleFullScreen():void{
if(this.stage.displayState==StageDisplayStae.FULL_SCREEN){
tthis.stage.displayState=StageDisplayState.NORMAL;
}esle{
this.stage.displayState=StageDisplayStae.FULL_SCREEN;
}
}另外需要在模板里面三个位置增加allowFullScreen,""true".
20.有朋友反映说加入了格式化jar包以后,没有反应,解决的方法是利用cmd执行eclipse加入参数-clean便可以,具体做法是:使用cmd进入eclipse目录,打进去eclipse -clean便可以解决。
21.如何建立虚拟tomcat的虚拟路径:在tomcat的目录conf里面建立文件夹Catalina,再建立文件夹localhost,编写mxl,名字与你的项目名一样,写入内容,例如:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="zzr" docBase="D:/myeclipse6.0workingspace/zzr/WebRoot" >
</Context>
23..改变flex中的主题:
C:/Program Files/Adobe/Flex Builder 3/sdks/3.2.0/frameworks/themes在这个目录中是flex的主题目录。其中HaloClassic是默认主题。
C:/Program Files/Adobe/Flex Builder 3/sdks/3.2.0/bin这个目录是flex中的编译目录
1.主题目录中的Ice.css文件拷贝到src下。-locale en_US -theme Ice.css编绎就可以了。这样当flex编绎时就用Ice.css为主题了。注意这个地方修改只会对当前工程有效果。
2.第二种方法就是改标签了。在Flex-config.xml中通过修改<theme>标签配置主题
在C:/Program Files/Adobe/Flex Builder 3/sdks/3.2.0/frameworks目录下的flex-config.xml文件。
把 <!--
<theme>
<filename>string</filename>
<filename>string</filename>
</theme>
-->
改成
<theme>
<filename>themes/Smoke/Smoke.css</filename>
</theme>
就能应用themes/Smoke/Smoke.css为主题了。
24.flex中的组件DataGrid中的注意点:
当用它的双击事件时,别忘了把doubleClickEnabled="true"设置为true,
itemDoubleClick="click(event)"
//双击时,打开相应的文章
private function click(e:Event):void{
navigateToURL(new URLRequest(e.currentTarget.selectedItem.link),"_blank");
}
25.给组件加上小手:
这两项可以让当鼠标经过组件时显示小手。buttonMode="true" useHandCursor="true"
26.除了验证器以外,还可以在vo编写的时候写一个isValid(各个字段)函数进行验证是否为空
27.经常在删除或者添加操作以后需要将数据清空,这时候不妨抽取出来写一个clearForm(),函数。
28.puremvc的耦合性非常好。
29.如何让titleWindow侦听外面点击关闭的脚本代码:<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import myComponents.MyLoginForm;
import mx.events.FlexMouseEvent;
private var helpWindow:TitleWindow;
private function showLogin():void {
// Create the TitleWindow container.
helpWindow = TitleWindow(PopUpManager.createPopUp(this,
MyLoginForm, false));
helpWindow.addEventListener("mouseDownOutside", removeForm);
}
private function removeForm(event:FlexMouseEvent):void {
PopUpManager.removePopUp(helpWindow);
}
]]>
</mx:Script>;让其加载完居中的脚本代码:private function handleCreationComplete():void {
// Center the TitleWindow container
// over the control that created it.
PopUpManager.centerPopUp(this);
} creationComplete="handleCreationComplete();"
30.验证器的错误信息风格和字体太小了,修改其方法如下:
.errorTip
{
fontSize: 14;
……
}
31.如何限制TextInput的输入仅为数字或者是字母:restrict=[0-9a-zA-Z];限制位数是maxchar.
32.跨域文件的调用方法:crossdomain.xml不是放在根目录下,而是在某个webapp下面,在flex中就需要在初始化的时候应用
Security.loadPolicyFile("http:// localhost:8080/aaa /crossdomain.xml");
33.vo类中如果不希望某个属性随对象发送使用元数据标签[Transient];
34.urlrequest如何传递变量参数:
var urlStr:string="";var urlreq:UrlRequest=new UrlRequest(urlStr);var urlVar:UrlVariables=new UrlVariables();
urlVar.username="黄记新";urlreq.data=urlVar;
35.使用puremvcConsonle控制台调试的方法:将facade改成debugFacade,再将<kapit:PureMVCConsole/>加入到主应用程序或者var p : PureMVCConsole = new PureMVCConsole(); p.showPopup()在初始化方法上面写上。
36.让数据表格不选中任何项的方法:dg.selectedIndex=-1;侦听数据表格单击以及双击的方法:dg.addEventListener(ListEvent.ITEM_CLICK, selectHandler); dg.addEventListener(ListEvent.ITEM_DOUBLE_CLICK, updateHandler);doubleClickEnabled="true"。
37.利用control做布局容器的导航非常有效,ControlBar - Panel 底部的条形控件。
38.利用函数进行绑定:// enable submit button if required fields are satisfied
private function enableSubmit( u:String, p:String, c:String, d:DeptEnum ):Boolean
{
return ( u != '' && p != '' && p == c && d != DeptEnum.NONE_SELECTED );
}
<mx:Button click="submit()"
label="提交"
enabled="{ enableSubmit( username.text, confirm.text, password.text, department.selectedItem as DeptEnum ) }"/>
39.去掉文本光标的两种方法: themeColor="#ffffff",将该属性设置与背景色一致; focusThickness="0"。
40.模仿穆迪导航条:<mx:Zoom id="zoomIn"
zoomWidthFrom="1"
zoomWidthTo="1.1"
zoomHeightFrom="1"
zoomHeightTo="1.1"
easingFunction="Bounce.easeOut"
duration="1000"/>
<mx:Zoom id="zoomBack"
zoomWidthFrom="1.1"
zoomWidthTo="1"
zoomHeightFrom="1.1"
zoomHeightTo="1"
easingFunction="Bounce.easeOut"
duration="1000"/><mx:Image x="445"
y="0"
source="assets/IMG_0642.JPG"
width="223"
height="167"
id="image2"
rollOver="image3.parent.setChildIndex(image2,2)"
rollOut="image3.parent.setChildIndex(image2,2)"
rollOverEffect="{zoomIn}"
rollOutEffect="{zoomBack}"/>
40.个人理解:什么是flex?flex是一个面向程序员,基于组件,使用mxml标签和as3.0脚本语言进行开发,同时基于事件驱动并且数据交互方式为异步的框架。
41.计时函数:
private function init():void
{
setTime();
var t:Timer = new Timer(1000);
t.addEventListener(TimerEvent.TIMER, setTime);
t.start();
}
private function setTime(e:TimerEvent = null):void
{
var date:Date = new Date();
var h:String = date.hours.toString().length == 1 ? '0' + date.hours.toString() : date.hours.toString();
var m:String = date.minutes.toString().length == 1 ? '0' + date.minutes.toString() : date.minutes.toString();
var s:String = date.seconds.toString().length == 1 ? '0' + date.seconds.toString() : date.seconds.toString();
time.text = h + ':' + m + '.' + s;
}
42.如何安装Photoshop的flex插件:http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex%5Fskins下载,解压后的目录放到ps安装目录便可。
43.失效机制和标志变量互作用示例:
protected var selectedIndexChanged:Boolean=false;
protected var animateProperty:AnimateProperty;
private var _selectedIndex:int=0;
private var _selectedChild:UIComponent;
[Bindable("change")]
public function get selectedIndex():int
{
return _selectedIndex;
}
public function set selectedIndex(value:int):void
{
if (_selectedIndex == value)
return;
_selectedIndex=value;
selectedIndexChanged=true;
dispatchEvent(new Event('change'));
this.invalidateProperties();
}
[Bindable("change")]
public function get selectedChild():UIComponent
{
return _selectedChild;
}
public function set selectedChild(value:UIComponent):void
{
if (_selectedChild == value)
return;
_selectedChild=value;
for (var i:int=0; i < orderedChildren.length; i++)
{
if (orderedChildren[i] == value)
{
this.selectedIndex=i;
break;
}
}
}
[Bindable]
public function get currentPosition():Number
{
return _currentPosition;
}
public function set currentPosition(value:Number):void
{
_currentPosition=value;
invalidateDisplayList();
}
private function itemClickHandler(e:MouseEvent):void
{
trace(Image(e.currentTarget).source)
this.selectedChild=e.currentTarget as UIComponent;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var centerPointOfCircle:Point=new Point(unscaledWidth * 0.5, unscaledHeight * 0.5);
var maxChildWidth:Number=0;
var child:UIComponent;
for (var i:int=0; i < orderedChildren.length; i++)
{
child=orderedChildren[i] as UIComponent;
child.setActualSize(child.getExplicitOrMeasuredWidth(), child.getExplicitOrMeasuredHeight());
maxChildWidth=Math.max(child.width, maxChildWidth);
}
var childPaddingInRadians:Number;
var childDistanceInRadians:Number; //实际的距离
childPaddingInRadians=(2 * Math.PI) / (numChildren); //孩子之间的弧度差
radius=(unscaledWidth / 2) - (maxChildWidth / 2); //求半径
for (var j:int=0; j < orderedChildren.length; j++)
{
child=orderedChildren[j] as UIComponent;
childDistanceInRadians=(j * childPaddingInRadians) + radianOffset - (currentPosition * childPaddingInRadians);
trace(childDistanceInRadians);
var newPoint:Point=getPointOnCircle(centerPointOfCircle, radius, childDistanceInRadians);
childCenterMove(child, newPoint);
}
}
override protected function commitProperties():void
{
super.commitProperties();
if (selectedIndexChanged)
{
selectedIndexChanged=false;
if (!animateProperty)
{
animateProperty=new AnimateProperty(this);
}
if (!animateProperty.isPlaying)
{
//Current position can get bigger and bigger, let's ensure we stay real and realize that it is just a factor
//of the number of children
trace("我是当前位置,目前没有被赋值,当我被赋值的时候我将调用失效方法更新列表"+currentPosition);
currentPosition%=numChildren;
if (currentPosition < 0)
{
currentPosition=numChildren + currentPosition;
}
}
//Determine if it is easier to move right or left around the circle to get to our new position
var newPosition:Number;
var moveVector:Number=selectedIndex - currentPosition;
var moveScalar:Number=Math.abs(moveVector);
if (moveScalar > (numChildren / 2))
{
if (moveVector < 0)
{
newPosition=numChildren + selectedIndex;
}
else
{
newPosition=(selectedIndex - numChildren);
}
}
else
{
newPosition=selectedIndex;
}
animateProperty.property="currentPosition";
animateProperty.fromValue=currentPosition;
animateProperty.toValue=newPosition;
//The duration of this effect is based on how far we must move. This way a one position move is not painfully slow
animateProperty.duration=700 * Math.abs(currentPosition - newPosition);
animateProperty.easingFunction=Quadratic.easeInOut;
// animateProperty.easingFunction=Quadratic.easeInOut;
animateProperty.suspendBackgroundProcessing=true;
animateProperty.play();
trace(currentPosition);
}
}
44.AnimateProperty 效果可为组件的属性或样式设置动画效果。可通过设置属性名称、属性的开始值和结束值来设置动画效果。此效果会将该属性设置为初始值,然后在播放效果期间更新此属性值,直到到达结束值。
例如,要更改 Button 控件的宽度,您可以指定 width 作为要设置动画的属性,并指定效果的起始值和最终宽度值。
45.镶嵌按钮图标:
<?xml version="1.0" encoding="utf-8"?>
<mx:Button xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:icon>
@Embed(source="assets/icon_expand_up.png")
</mx:icon>
</mx:Button>,让文本域得到焦点不发光:<?xml version="1.0" encoding="utf-8"?>
<mx:TextArea xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:focusThickness>
0
</mx:focusThickness>
</mx:TextArea>
46.使用Alert询问用户是否要删除:
private function deleteBtnClick(event:MouseEvent):void
{
var alert:Alert=Alert.show("确定删除", "删除?", 3, formView, alertClickHandler);
}
// Event handler function for displaying the selected Alert button.
private function alertClickHandler(event:CloseEvent):void
{
if (event.detail == Alert.YES)
{
}
}
47.接上,使用Alert控制显示Label,默认为yes和no,现在修改为是和否,只需在show方法之前加上Alert.yesLabel="是"和Alert.yesLabel="否"
48.最佳实践:表格列表容不下字数的时候有两种解决方法:wordWrap=true;或者指定渲染器itemRenderer=“mx.controls.Label”,但前者撑起来以后可能会让其他项变形(例如渲染器按钮)所以还是推荐后者。
49.获取随机颜色:Math.random()*0xffffff.
50.如何将公共代码抽取出来独立成一个文件:使用include "xx.inc";一些列举比较多的属性也可以抽取出来,比如中国的省份;
51.网页当中标题的显示:pageTitle属性可以显示标题。
52.不断更新……