flex常用,个人总结flex各种常用代码

//获得屏幕的分辨率 此内容来自帝巴必: http://www.89ye.com
var x:Number=Capabilities.screenResolutionX; 此内容来自帝巴必: http://www.89ye.com
var y:Number=Capabilities.screenResolutionY; 此内容来自帝巴必: http://www.89ye.com
Alert.show( “x=” +x+ “y=” +y);
第二种方法 帝巴必http://www.89ye.com 综合娱乐门户
Alert.show(stage.fullScreenWidth+ “==” +stage.fullScreenHeight);
//获得 stage(工作区)的宽、高 此内容来自帝巴必: http://www.89ye.com
Alert.show(stage.stageWidth+”==”+stage.stageHeight); 此内容来自帝巴必: http://www.89ye.com
//读取xml文件
private function readxml2():void 帝巴必http://www.89ye.com 综合娱乐门户
{ 此内容来自帝巴必: http://www.89ye.com
var urlrequest:URLRequest=new URLRequest(“file/stu.xml”);
var urlloader:URLLoader=new URLLoader(urlrequest);
urlloader.addEventListener(Event.COMPLETE, completehandler);
} 帝巴必http://www.89ye.com 综合娱乐门户
private function completehandler(event:Event):void
{ 此内容来自帝巴必: http://www.89ye.com
var xml:XML=new XML(event.target.data); 帝巴必http://www.89ye.com 综合娱乐门户
// var arr:Array=new Array(xml); 帝巴必http://www.89ye.com 综合娱乐门户
this.dg.dataProvider=xml.children();
this.tree.dataProvider=xml;
this.cb.dataProvider=xml.children();
// this.hlist.dataProvider=xml.children(); 帝巴必http://www.89ye.com 综合娱乐门户
} 此内容来自帝巴必: http://www.89ye.com
//flex 获得系统路径
var add:String=ExternalInterface.call(“window.location.href.toString”,1);
Alert.show(add);
//背景颜色不断变化
private function changeBG():void{
var mytime:Timer=new Timer(2000); 此内容来自帝巴必: http://www.89ye.com
mytime.addEventListener(TimerEvent.TIMER,changHandle);
mytime.start(); 此内容来自帝巴必: http://www.89ye.com
}
private function changHandle(e:TimerEvent):void{ 帝巴必http://www.89ye.com 综合娱乐门户
this.setStyle(“backgroundColor”,Math.random()* 0xffffff); 帝巴必http://www.89ye.com 综合娱乐门户
}
//获得键盘按下的键的值
public function getCode():void
{ 此内容来自帝巴必: http://www.89ye.com
btn.addEventListener(KeyboardEvent.KEY_DOWN, keyHandle); 此内容来自帝巴必: http://www.89ye.com
} 帝巴必http://www.89ye.com 综合娱乐门户
function keyHandle(event:KeyboardEvent):void
{
Alert.show(“你按下了:” + String.fromCharCode(event.charCode));
} 此内容来自帝巴必: http://www.89ye.com
//动态加载不同界面 帝巴必http://www.89ye.com 综合娱乐门户
import commont.Two;
import commont.One; 此内容来自帝巴必: http://www.89ye.com
var t:Two= new Two();
]var o:One= new _disibledevent=>
var phone1:Class;
//日期中文标题 帝巴必http://www.89ye.com 综合娱乐门户
// 选择日期 dateChoose
function disDate(): void {
txtDate.text=fm.format(dtchoose.selectedDate.toLocaleDateString());
}
//flex 中添加html标记
此内容来自帝巴必: http://www.89ye.com
帝巴必http://www.89ye.com 综合娱乐门户
帝巴必http://www.89ye.com 综合娱乐门户
此内容来自帝巴必: http://www.89ye.com
你 哈 !!!
帝巴必http://www.89ye.com 综合娱乐门户
]]>
巴必http://www.89ye.com 综合娱乐门户
帝巴必http://www.89ye.com 综合娱乐门户
//flex 带下划线的链接
this .lblLink.htmlText= “
新 闻
” ;
rollOut="focusManager.activate()" styleName=" Label " 帝巴必http://www.89ye.com 综合娱乐门户
creationComplete="link()" />
.Label { text-roll-over-color : red ; text-decoration : underline ; background-color : green ; font-size : 12px ; text-selected-color : red ;}
//flex 转向 URL
V ar url:URLRequest=new URLRequest( “ http://www.google.cn ” ); 帝巴必http://www.89ye.com 综合娱乐门户
navigateToURL(url, ” _self ” );// 在本页打开
navigateToURL(url, ” _blank ” );// 在新的一页打开 帝巴必http://www.89ye.com 综合娱乐门户
//弹出对话框
——— 非模式打开———
PopUpManager.createPopUp( this , 类 (界面)的名称 );
———模式打开——— 此内容来自帝巴必: http://www.89ye.com
var ep: Main = new Main ();
PopUpManager.addPopUp(ep, this , true ); // 界面,打开窗口父类,是否模式 此内容来自帝巴必: http://www.89ye.com
PopUpManager.centerPopUp(ep); // 在父类窗口居中 帝巴必http://www.89ye.com 综合娱乐门户
//—–Alert的用法
public function test(): void 帝巴必http://www.89ye.com 综合娱乐门户
{
var glow:GlowFilter= new GlowFilter();
glow.color=StyleManager.getColorName( “blue” ); // 边框颜色 此内容来自帝巴必: http://www.89ye.com
glow.strength=5; 此内容来自帝巴必: http://www.89ye.com
glow.alpha=0.8;
var alert:Alert=Alert.show( ” 是否选择 ” , ” 提示 ” ,Alert.YES|Alert.NO, this ,alertHandle); 此内容来自帝巴必: http://www.89ye.com
alert.filters=[glow];
} 帝巴必http://www.89ye.com 综合娱乐门户
private function alertHandle(event:CloseEvent): void {
if (event.detail==Alert.YES){ 帝巴必http://www.89ye.com 综合娱乐门户
lbl.text= ” 是 ” ; 此内容来自帝巴必: http://www.89ye.com
} else {
lbl.text= ” 否 ” ;
} 帝巴必http://www.89ye.com 综合娱乐门户
} 帝巴必http://www.89ye.com 综合娱乐门户
帝巴必http://www.89ye.com 综合娱乐门户
帝巴必http://www.89ye.com 综合娱乐门户
//flex Com bo box添加 – 请选择- 帝巴必http://www.89ye.com 综合娱乐门户
private function loadCB(){
var arr:Array= new Array( “- 请选择 -” );
for ( var i:int=1;iarr=i;
} 此内容来自帝巴必: http://www.89ye.com
this .cb.dataProvider=arr;
} 帝巴必http://www.89ye.com 综合娱乐门户
//combobox 选择的值和下标
private function selected(): void { 此内容来自帝巴必: http://www.89ye.com
Alert.show(cb.selectedItem.toString()+ " 下标 :" +cb.selectedIndex);
}
//鼠标移动变大,Button加图片,变手型 帝巴必http://www.89ye.com 综合娱乐门户
labelPlacement=" bottom " width=" 67 " useHandCursor=" true " buttonMode=" true " /> 帝巴必http://www.89ye.com 综合娱乐门户
private function changBig(): void {
this .btn.scaleX=1.5; 此内容来自帝巴必: http://www.89ye.com
this .btn.scaleY=1.5
} 此内容来自帝巴必: http://www.89ye.com
private function changSmall(): void {
this .btn.scaleX=1;
this .btn.scaleY=1; 此内容来自帝巴必: http://www.89ye.com
}
//flex panel 拖动效果 此内容来自帝巴必: http://www.89ye.com
private function _disibledevent=>
share.data.userName=txtUser.text;
share.flush(); 此内容来自帝巴必: http://www.89ye.com
//读取共享数据
var share:SharedObject=SharedObject.getLocal( “username” );
Alert.show(share.data.userName);
//jsp/html文件嵌入到flex中(需要把 flexiframe.swc 放在项目的flex_libs下) 帝巴必http://www.89ye.com 综合娱乐门户
A pplication标签内 xmlns:code= http://code.google.com/p/flex-iframe/ 此内容来自帝巴必: http://www.89ye.com 此内容来自帝巴必: http://www.89ye.com
//检查使用的操作系统 此内容来自帝巴必: http://www.89ye.com
private function checkOS(): void {
var os:String=Capabilities.os;
tt.text= " 你的操作系统是 :--" +os;
}
//检查所使用的浏览器
private function checkPlay(): void { 此内容来自帝巴必: http://www.89ye.com
var play:String=Capabilities.playerType; 此内容来自帝巴必: http://www.89ye.com
Alert.show(play); 此内容来自帝巴必: http://www.89ye.com
if (play== "ActiveX" ){
tt.text= " 你的浏览器是 --IE" ; 此内容来自帝巴必: http://www.89ye.com
} else if (play== "PlugIn" ){ 帝巴必http://www.89ye.com 综合娱乐门户
tt.text= " 你的浏览器是 --Mozilla-Firefox" ;
} else { 此内容来自帝巴必: http://www.89ye.com
tt.text= " 你的浏览器是 -- 其他 " ; 此内容来自帝巴必: http://www.89ye.com
} 此内容来自帝巴必: http://www.89ye.com
}
//检查player的版本和使用的语言 此内容来自帝巴必: http://www.89ye.com
private function other(): void {
var v:String=Capabilities.version;
var l:String=Capabilities.language; 帝巴必http://www.89ye.com 综合娱乐门户
tt.text= " 你的 flayer 版本号: --" +v+ 此内容来自帝巴必: http://www.89ye.com
"\r\n 你的语言是: --" +l; 帝巴必http://www.89ye.com 综合娱乐门户
}
//改变鼠标样式 帝巴必http://www.89ye.com 综合娱乐门户
[ Bindable ] 此内容来自帝巴必: http://www.89ye.com
[ Embed (source= "img/157.jpg" )]
public var cur:Class;
private function initCursor(event:Event){ 此内容来自帝巴必: http://www.89ye.com
CursorManager.setCursor(cur); 帝巴必http://www.89ye.com 综合娱乐门户
}
//设置 AdvancedDataGrid 的表头竖线为空
headerSortSeparatorSkin=" mx.skins.ProgrammaticSkin "
//获得鼠标坐标 此内容来自帝巴必: http://www.89ye.com
var cx:Number=CursorManager.currentCursorXOffset; 此内容来自帝巴必: http://www.89ye.com
var cy:Number=CursorManager.currentCursorYOffset; 帝巴必http://www.89ye.com 综合娱乐门户
var id:int=CursorManager.currentCursorID; 帝巴必http://www.89ye.com 综合娱乐门户
Alert.show( "x:=" +cx+ "y:=" +y+ "id=" +id);
Tags:  总结flex flex4代码 flex常用架构 flex代码 flex常用

延伸阅读

最新评论

发表评论