flex各种用法
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
private function completehandler(event:Event):void
{
var xml:XML=new XML(event.target.data);
// var arr:Array=new Array(xml);
this.dg.dataProvider=xml.children();
var alert:Alert=Alert.show("是否选择","提示",Alert.YES|Alert.NO,this,alertHandle);
alert.filters=[glow];
}
private function alertHandle(event:CloseEvent):void{
//在Flex中获取当前窗口的长度与宽度使用下面的方法:
var w = Application.application.width;
var h = Application.application.height;
//绝对定位TitleWindow
var myTitleWindow:MyTitleWindow= MyTitleWindow(PopUpManager.createPopUp(DisplayObject(Application.application),MyTitleWindow,true));
myTitleWindow.x = (w-myTitleWindow.width)/2;
myTitleWindow.y = 100;
//获得stage(工作区)的宽、高
Alert.show(stage.stageWidth+"=="+stage.stageHeight);
//读取xml文件
private function readxml2():void
<mx:DateChooser id="dtchoose" x="219" y="83" dayNames="[日,一,二,三,四,五,六]" monthNames="[一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月]" change="disDate()" minYear="2007"/>
btn.addEventListener(KeyboardEvent.KEY_DOWN, keyHandle);
}
function keyHandle(event:KeyboardEvent):void
{
Alert.show("你按下了:" + String.fromCharCode(event.charCode));
</mx:Panel>
private function ondragStart(event:MouseEvent):void{
Panel(event.target).startDrag();
}
private function ondragStop(event:MouseEvent):void{
Panel(event.target).stopDrag();
Alert.show(add);
//背景颜色不断变化
private function changeBG():void{
var mytime:Timer=new Timer(2000);
mytime.addEventListener(TimerEvent.TIMER,changHandle);
mytime.start();
<mx:htmlText>
<!--[CDATA[
<input type='file'/>
<a href="http://www.baidu.com" mce_href="http://www.baidu.com">你哈!!!</a>
]]-->
</mx:htmlText>
</mx:TextArea>
//flex带下划线的链接
}
private function changHandle(e:TimerEvent):void{
this.setStyle("backgroundColor",Math.random()* 0xffffff);
}
//获得键盘按下的键的值
public function getCode():void
{
{
var urlrequest:URLRequest=new URLRequest("file/stu.xml");
var urlloader:URLLoader=new URLLoader(urlrequest);
urlloader.addEventListener(Event.COMPLETE, completehandler);
Alert.show(share.data.userName);
//jsp/html文件嵌入到flex中(需要把flexiframe.swc放在项目的flex_libs下)
//鼠标移动变大,Button加图片,变手型
<mx:Button x="72" y="80" label="Button" click="test()" mouseMove="changBig()" mouseOut="changSmall()" id="btn" height="52" icon="@Embed(source='img/3.jpg')"
}
private function showTwo():void{
tw.removeAllChildren();
tw.addChild(t);
}
//flex绑定图片
[Bindable]
[Embed(source="img/1.jpg")]
public var phone1:Class;
//日期中文标题
PopUpManager.createPopUp(this,类(界面)的名称);
---------模式打开---------
var ep:Main=new Main ();
PopUpManager.addPopUp(ep,this,true);//界面,打开窗口父类,是否模式
PopUpManager.centerPopUp(ep);//在父类窗口居中
this.tree.dataProvider=xml;
this.cb.dataProvider=xml.children();
// this.hlist.dataProvider=xml.children();
}
//flex获得系统路径
var add:String=ExternalInterface.call("window.location.href.toString",1);
private function selected():void{
Alert.show(cb.selectedItem.toString()+"下标:"+cb.selectedIndex);
}
<mx:ComboBox x="194" y="80" id="cb" creationComplete="loadCB()" change="selected()">
//选择日期dateChoose
function disDate():void{
txtDate.text=fm.format(dtchoose.selectedDate.toLocaleDateString());
}
//flex中添加html标记
<mx:TextArea id="text" creationComplete="init()" width="248" height="59">
if(event.detail==Alert.YES){
lbl.text="是";
}else{
lbl.text="否";
}
}
<mx:Button x="62" y="80" label="Button" click="test()"/>
<mx:Label x="62" y="37" text="Label" width="65" id="lbl"/>
labelPlacement="bottom" width="67" useHandCursor="true" buttonMode="true"/>
private function changBig():void{
this.btn.scaleX=1.5;
this.btn.scaleY=1.5
}
private function changSmall():void{
//获得屏幕的分辨率
var x:Number=Capabilities.screenResolutionX;
var y:Number=Capabilities.screenResolutionY;
Alert.show("x="+x+"y="+y);
//第二种方法
Alert.show(stage.fullScreenWidth+"=="+stage.fullScreenHeight);
}
//动态加载不同界面
import commont.Two;
import commont.One;
var t:Two=new Two();
var o:One=new One();
private function showOne():void{
tw.removeAllChildren();
tw.addChild(o);
}
//写入共享数据
share=SharedObject.getLocal("username");
share.data.userName=txtUser.text;
share.flush();
//读取共享数据
var share:SharedObject=SharedObject.getLocal("username");
//flex Combobox添加–请选择-
private function loadCB(){
var arr:Array=new Array("-请选择-");
for(var i:int=1;i<10;i++){
arr=i;
}
this.cb.dataProvider=arr;
}ຫໍສະໝຸດ Baidu
//combobox选择的值和下标
//flex转向URL
Var url:URLRequest=new URLRequest(“http://www.google.cn”);
navigateToURL(url,”_self”);//在本页打开
navigateToURL(url,”_blank”);//在新的一页打开
//弹出对话框
---------非模式打开---------
//-----Alert的用法
public function test():void
{
var glow:GlowFilter=new GlowFilter();
glow.color=StyleManager.getColorName("blue");//边框颜色
glow.strength=5;
glow.alpha=0.8;
this.lblLink.htmlText="<a href="http://www.google.com" mce_href="http://www.google.com" target='_blank'>新闻</a>";
<mx:Label x="524" y="393" text="Hellollll" id="lblLink" rollOver="focusManager.deactivate()" color="blue" opaqueBackground="#ffffff"
rollOut="focusManager.activate()" styleName="Label"
creationComplete="link()"/>
.Label{text-roll-over-color:red; text-decoration:underline; background-color:green; font-size:12px; text-selected-color:red;}
this.btn.scaleX=1;
this.btn.scaleY=1;
}
//flex panel拖动效果
<mx:Panel x="194" y="125" width="192" height="121" layout="absolute" id="panel" mouseDown="ondragStart(event)" mouseUp="ondragStop(event)">
private function completehandler(event:Event):void
{
var xml:XML=new XML(event.target.data);
// var arr:Array=new Array(xml);
this.dg.dataProvider=xml.children();
var alert:Alert=Alert.show("是否选择","提示",Alert.YES|Alert.NO,this,alertHandle);
alert.filters=[glow];
}
private function alertHandle(event:CloseEvent):void{
//在Flex中获取当前窗口的长度与宽度使用下面的方法:
var w = Application.application.width;
var h = Application.application.height;
//绝对定位TitleWindow
var myTitleWindow:MyTitleWindow= MyTitleWindow(PopUpManager.createPopUp(DisplayObject(Application.application),MyTitleWindow,true));
myTitleWindow.x = (w-myTitleWindow.width)/2;
myTitleWindow.y = 100;
//获得stage(工作区)的宽、高
Alert.show(stage.stageWidth+"=="+stage.stageHeight);
//读取xml文件
private function readxml2():void
<mx:DateChooser id="dtchoose" x="219" y="83" dayNames="[日,一,二,三,四,五,六]" monthNames="[一月,二月,三月,四月,五月,六月,七月,八月,九月,十月,十一月,十二月]" change="disDate()" minYear="2007"/>
btn.addEventListener(KeyboardEvent.KEY_DOWN, keyHandle);
}
function keyHandle(event:KeyboardEvent):void
{
Alert.show("你按下了:" + String.fromCharCode(event.charCode));
</mx:Panel>
private function ondragStart(event:MouseEvent):void{
Panel(event.target).startDrag();
}
private function ondragStop(event:MouseEvent):void{
Panel(event.target).stopDrag();
Alert.show(add);
//背景颜色不断变化
private function changeBG():void{
var mytime:Timer=new Timer(2000);
mytime.addEventListener(TimerEvent.TIMER,changHandle);
mytime.start();
<mx:htmlText>
<!--[CDATA[
<input type='file'/>
<a href="http://www.baidu.com" mce_href="http://www.baidu.com">你哈!!!</a>
]]-->
</mx:htmlText>
</mx:TextArea>
//flex带下划线的链接
}
private function changHandle(e:TimerEvent):void{
this.setStyle("backgroundColor",Math.random()* 0xffffff);
}
//获得键盘按下的键的值
public function getCode():void
{
{
var urlrequest:URLRequest=new URLRequest("file/stu.xml");
var urlloader:URLLoader=new URLLoader(urlrequest);
urlloader.addEventListener(Event.COMPLETE, completehandler);
Alert.show(share.data.userName);
//jsp/html文件嵌入到flex中(需要把flexiframe.swc放在项目的flex_libs下)
//鼠标移动变大,Button加图片,变手型
<mx:Button x="72" y="80" label="Button" click="test()" mouseMove="changBig()" mouseOut="changSmall()" id="btn" height="52" icon="@Embed(source='img/3.jpg')"
}
private function showTwo():void{
tw.removeAllChildren();
tw.addChild(t);
}
//flex绑定图片
[Bindable]
[Embed(source="img/1.jpg")]
public var phone1:Class;
//日期中文标题
PopUpManager.createPopUp(this,类(界面)的名称);
---------模式打开---------
var ep:Main=new Main ();
PopUpManager.addPopUp(ep,this,true);//界面,打开窗口父类,是否模式
PopUpManager.centerPopUp(ep);//在父类窗口居中
this.tree.dataProvider=xml;
this.cb.dataProvider=xml.children();
// this.hlist.dataProvider=xml.children();
}
//flex获得系统路径
var add:String=ExternalInterface.call("window.location.href.toString",1);
private function selected():void{
Alert.show(cb.selectedItem.toString()+"下标:"+cb.selectedIndex);
}
<mx:ComboBox x="194" y="80" id="cb" creationComplete="loadCB()" change="selected()">
//选择日期dateChoose
function disDate():void{
txtDate.text=fm.format(dtchoose.selectedDate.toLocaleDateString());
}
//flex中添加html标记
<mx:TextArea id="text" creationComplete="init()" width="248" height="59">
if(event.detail==Alert.YES){
lbl.text="是";
}else{
lbl.text="否";
}
}
<mx:Button x="62" y="80" label="Button" click="test()"/>
<mx:Label x="62" y="37" text="Label" width="65" id="lbl"/>
labelPlacement="bottom" width="67" useHandCursor="true" buttonMode="true"/>
private function changBig():void{
this.btn.scaleX=1.5;
this.btn.scaleY=1.5
}
private function changSmall():void{
//获得屏幕的分辨率
var x:Number=Capabilities.screenResolutionX;
var y:Number=Capabilities.screenResolutionY;
Alert.show("x="+x+"y="+y);
//第二种方法
Alert.show(stage.fullScreenWidth+"=="+stage.fullScreenHeight);
}
//动态加载不同界面
import commont.Two;
import commont.One;
var t:Two=new Two();
var o:One=new One();
private function showOne():void{
tw.removeAllChildren();
tw.addChild(o);
}
//写入共享数据
share=SharedObject.getLocal("username");
share.data.userName=txtUser.text;
share.flush();
//读取共享数据
var share:SharedObject=SharedObject.getLocal("username");
//flex Combobox添加–请选择-
private function loadCB(){
var arr:Array=new Array("-请选择-");
for(var i:int=1;i<10;i++){
arr=i;
}
this.cb.dataProvider=arr;
}ຫໍສະໝຸດ Baidu
//combobox选择的值和下标
//flex转向URL
Var url:URLRequest=new URLRequest(“http://www.google.cn”);
navigateToURL(url,”_self”);//在本页打开
navigateToURL(url,”_blank”);//在新的一页打开
//弹出对话框
---------非模式打开---------
//-----Alert的用法
public function test():void
{
var glow:GlowFilter=new GlowFilter();
glow.color=StyleManager.getColorName("blue");//边框颜色
glow.strength=5;
glow.alpha=0.8;
this.lblLink.htmlText="<a href="http://www.google.com" mce_href="http://www.google.com" target='_blank'>新闻</a>";
<mx:Label x="524" y="393" text="Hellollll" id="lblLink" rollOver="focusManager.deactivate()" color="blue" opaqueBackground="#ffffff"
rollOut="focusManager.activate()" styleName="Label"
creationComplete="link()"/>
.Label{text-roll-over-color:red; text-decoration:underline; background-color:green; font-size:12px; text-selected-color:red;}
this.btn.scaleX=1;
this.btn.scaleY=1;
}
//flex panel拖动效果
<mx:Panel x="194" y="125" width="192" height="121" layout="absolute" id="panel" mouseDown="ondragStart(event)" mouseUp="ondragStop(event)">