Flex 学习小结(5)

1 调用module
新建一个module:
<mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function showModuleMessage():void
{
Alert.show("单击模块");
}
]]>
</mx:Script>
<mx:Button x="129" y="89" label="Button" click="showModuleMessage()"/>

</mx:Module>
然后在主程序中,直接把这个module拖拉进去,即:
<mx:Script>
<![CDATA[
private function loadModule(http://www.cnblogs.com/jackyrong/admin/String):void
{
currentModule.url=url;
currentModule.loadModule();
}

]]>
</mx:Script>
<mx:ModuleLoader width="50%" height="50%" id="currentModule" click='loadModule("ModuleStu.swf")' horizontalCenter="0" verticalCenter="0">
</mx:ModuleLoader>
这里通过moduleloader来去调用这个module

2 下面的例子显示titlewindows的用法:
首先搞一个登陆的对话框:
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml" showCloseButton="true" close="PopUpManager.removePopUp(this);" >
<mx:Script>
<![CDATA[
//引入需要的包
import mx.managers.PopUpManager;
import mx.controls.TextInput;
//声明两个TextInput组件用于与舞台进行数据通信
public var userName:TextInput;
public var password:TextInput;
//定义一个函数传递数据并关闭窗口
private function processLogin():void {
//将输入传递给舞台上的TextInput组件
userName.text=username_txt.text;
password.text=password_txt.text;
//移除窗口
PopUpManager.removePopUp(this);
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem label="用户名">
<mx:TextInput id="username_txt" width="100%"/>
</mx:FormItem>
<mx:FormItem label="密码">
<mx:TextInput id="password_txt" displayAsPassword="true" width="100%"/>
</mx:FormItem>
</mx:Form>
<mx:HBox>
<mx:Button click="processLogin();" label="登录"/>
<mx:Button label="取消" click="PopUpManager.removePopUp(this);"/>
</mx:HBox>
</mx:TitleWindow>

然后在一个mxml中,建立一个button,两个文本框,当点button时,以模态方式打开登陆窗口,
当在登陆窗口中输入内容后,在原来的文本框中显示输入的用户名和密码:
<mx:Script>
<![CDATA[
//引入PopUpManager类
import mx.managers.PopUpManager;
//定义一个函数弹出对话框
private function showLogin():void {
//使用PopUpManager创建一个模式的弹出LoginWindow对话框,并得到引用
var login_win:LoginWindow =LoginWindow(PopUpManager.createPopUp(this, LoginWindow,true));
//设定弹出窗口的位置为舞台的中心
PopUpManager.centerPopUp(login_win);
//设定弹出窗口的标题
login_win.title="登录";
//将显示的TextInput的引用传递给弹出窗口
login_win.userName=userName_txt;
login_win.password=password_txt;
}
]]>
</mx:Script>
<mx:Button id="login_btn" click="showLogin();" label="Login" horizontalCenter="0" verticalCenter="0"/>
<!--用于显示窗口输入的内容-->
<mx:TextInput id="userName_txt" horizontalCenter="0" verticalCenter="64"/>
<mx:TextInput id="password_txt" horizontalCenter="0" verticalCenter="88"/>


3 alert对话框:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Panel x="10" y="45" width="436" height="259" layout="absolute" fontSize="12" title="Alert组件示例">
<mx:Button x="39" y="47" label="点 我" click="onClick()" fontWeight="normal"/>
<mx:Button x="116" y="47" label="点 我" fontWeight="normal" click="onClickTitle()"/>
<mx:Button x="204" y="47" label="点 我" fontWeight="normal" click="onClickConfrm()"/>
<mx:Label x="39" y="149" id="alertResult" fontWeight="bold" color="#2500C7" width="219"/>
<mx:Button x="295" y="47" label="点 我" fontWeight="normal" click="onClickHandler()"/>
</mx:Panel>
<mx:Script>
<![CDATA[
import mx.events.CloseEvent;
import mx.controls.Alert;

internal function onClick():void
{
Alert.show("Hello World!");
}

internal function onClickTitle():void
{ Alert.show("Hello World!","这里是标题");
}

internal function onClickConfrm():void
{
Alert.yesLabel="是";
Alert.noLabel="否";
Alert.show("Hello World!","这里是标题",4,this,onCloseHandler);
}

internal function onCloseHandler(evt:CloseEvent):void
{ if(evt.detail==Alert.YES)
{
alertResult.text = "你选择的是:“是”!";
}
else
{
alertResult.text = "你选择的是:“否”!";
}
}

internal function onClickHandler():void
{
Alert.yesLabel="是";
Alert.noLabel="否";
Alert.cancelLabel="取消";
Alert.show("Hello World!","这里是标题",1|2|8,this,onCloseHandler);
}
]]>
</mx:Script>
</mx:Application>

你可能感兴趣的:(UI,Flex,Flash,Adobe,小结)