// 獲得屏幕的分辨率
var x:Number=Capabilities.screenResolutionX;
var y:Number=Capabilities.screenResolutionY;
Alert.show("x="+x+"y="+y);
// 第二種方法
Alert.show(stage.fullScreenWidth+"=="+stage.fullScreenHeight);
// 在 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
{
var urlrequest:URLRequest=new URLRequest("file/stu.xml");
var urlloader:URLLoader=new URLLoader(urlrequest);
urlloader.addEventListener(Event.COMPLETE, completehandler);
}
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();
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);
Alert.show(add);
// 背景顏色不斷變化
private function changeBG():void{
var mytime:Timer=new Timer(2000);
mytime.addEventListener(TimerEvent.TIMER,changHandle);
mytime.start();
}
private function changHandle(e:TimerEvent):void{
this.setStyle("backgroundColor",Math.random()* 0xffffff);
}
// 獲得鍵盤按下的鍵的值
public function getCode():void
{
btn.addEventListener(KeyboardEvent.KEY_DOWN, keyHandle);
}
function keyHandle(event:KeyboardEvent):void
{
Alert.show(" 你按下了 :" + String.fromCharCode(event.charCode));
}
// 動態加載不同界面
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);
}
private function showTwo():void{
tw.removeAllChildren();
tw.addChild(t);
}
//flex 綁定圖片
[Bindable]
[Embed(source="img/1.jpg")]
public var phone1:Class;
// 日期中文標題
<mx:DateChooser id="dtchoose" x="219" y="83" dayNames="[ 日 , 一 , 二 , 三 , 四 , 五 , 六 ]" monthNames="[ 一月 , 二月 , 三月 , 四月 , 五月 , 六月 , 七月 , 八月 , 九月 , 十月 , 十一月 , 十二月 ]" change="disDate()" minYear="2007"/>
// 選擇日期 dateChoose
function disDate():void{
txtDate.text=fm.format(dtchoose.selectedDate.toLocaleDateString());
}
//flex 中添加 html 標記
<mx:TextArea id="text" creationComplete="init()" width="248" height="59">
<mx:htmlText>
<!--[CDATA[
<input type='file'/>
<a href="http://www.baidu.com" mce_href="http://www.baidu.com"> 你哈 !!!</a>
]]-->
</mx:htmlText>
</mx:TextArea>
//flex 帶下劃線 的鏈接
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;}
//flex 轉向 URL
Var url:URLRequest=new URLRequest(“http://www.google.cn”);
navigateToURL(url, ” _self ” );// 在本頁打開
navigateToURL(url, ” _blank ” );// 在新的一頁打開
// 彈出對話框
--------- 非模式打開 ---------
PopUpManager.createPopUp(this, 類(界面)的名稱 );
--------- 模式打開 ---------
var ep:Main=new Main ();
PopUpManager.addPopUp(ep,this,true);// 界面,打開窗口父類,是否模式
PopUpManager.centerPopUp(ep);// 在父類窗口居中
//-----Alert 的用法
public function test():void
{
var glow:GlowFilter=new GlowFilter();
glow.color=StyleManager.getColorName("blue");// 邊框顏色
glow.strength=5;
glow.alpha=0.8;
var alert:Alert=Alert.show(" 是否選擇 "," 提示 ",Alert.YES|Alert.NO,this,alertHandle);
alert.filters=[glow];
}
private function alertHandle(event:CloseEvent):void{
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"/>
//flex Combobox 添加 –請選擇 -
private function loadCB(){
var arr:Array=new Array("- 請選擇 -");
for(var i:int=1;i<10;i++){
arr=i;
}
this.cb.dataProvider=arr;
}
//combobox 選擇的值 和下標
private function selected():void{
Alert.show(cb.selectedItem.toString()+" 下標 :"+cb.selectedIndex);
}
<mx:ComboBox x="194" y="80" id="cb" creationComplete="loadCB()" change="selected()">
// 鼠標 移動變大, 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')"
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{
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)">
</mx:Panel>
private function ondragStart(event:MouseEvent):void{
Panel(event.target).startDrag();
}
private function ondragStop(event:MouseEvent):void{
Panel(event.target).stopDrag();
}
// 寫入 共享數據
share=SharedObject.getLocal("username");
share.data.userName=txtUser.text;
share.flush();
// 讀取 共享數據
var share:SharedObject=SharedObject.getLocal("username");
Alert.show(share.data.userName);
//jsp/html 文件嵌入到 flex 中(需要把 flexiframe.swc 放在項目的 flex_libs 下)
Application 標籤內 xmlns:code=http://code.google.com/p/flex-iframe/
<mx:HDividedBox x="0" y="10" width="100%" height="500">
<mx:Panel width="30%" height="500" layout="absolute">
</mx:Panel>
<mx:Panel width="70%" height="500" layout="absolute">
<code:IFrame id="frm" source="file/ 萬年曆 .html" height="100%" width="100%"/><!- 這是最重要的 - à
</mx:Panel>
</mx:HDividedBox>
// 檢查 使用的操作系統
private function checkOS():void{
var os:String=Capabilities.os;
tt.text=" 你的操作系統是 :--"+os;
}
// 檢查 所使用的瀏覽器
private function checkPlay():void{
var play:String=Capabilities.playerType;
Alert.show(play);
if(play=="ActiveX"){
tt.text=" 你的瀏覽器是 --IE";
}else if(play=="PlugIn"){
tt.text=" 你的瀏覽器是 --Mozilla-Firefox";
}else{
tt.text=" 你的瀏覽器是 -- 其他 ";
}
}
// 檢查 player 的版本和使用的語言
private function other():void{
var v:String=Capabilities.version;
var l:String=Capabilities.language;
tt.text=" 你的 flayer 版本號: --"+v+
"/r/n 你 的語言是: --"+l;
}
// 改變 鼠標樣式
[Bindable]
[Embed(source="img/157.jpg")]
public var cur:Class;
private function initCursor(event:Event){
CursorManager.setCursor(cur);
}
// 設置 AdvancedDataGrid 的表頭豎線爲空
headerSortSeparatorSkin="mx.skins.ProgrammaticSkin"
// 獲得 鼠標座標
var cx:Number=CursorManager.currentCursorXOffset;
var cy:Number=CursorManager.currentCursorYOffset;
var id:int=CursorManager.currentCursorID;
Alert.show("x:="+cx+"y:="+y+"id="+id);