包的使用-简单登录系统(初学如有错误请包涵)
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;//导入要用的函数包
public class Denglu extends MovieClip
{
public function Denglu()
{
str();//声明一个str的新函数
}
public function str()
{
btn1.label = "确定";
btn2.label = "取消";//为按钮命名
fanhui.visible = false;//设置fanhui页面的visible属性为false即不可见
zhangHao_text.selectable = false;//设置输入账号的的文本框中的内容不可复制
miMa_text.selectable = false;
miMa_text.displayAsPassword = true;//设置输入的密码为密码文本字段即为*
btn1.addEventListener(MouseEvent.CLICK,onBtn1Click);
btn2.addEventListener(MouseEvent.CLICK,onBtn2Click);
fanhui.return_btn.addEventListener(MouseEvent.CLICK ,onBtn3Click);//为按钮添加相关事件
}
private function onBtn1Click(e:MouseEvent ):void//执行确定按钮的相关事件
{
if (zhangHao_text.text == "www" && miMa_text.text == "123")
{
trace("登录成功");
} //条件满足输出"登录成功"
else
{
fanhui.visible = true;
} //条件不满足fanhui页面显示
}
private function onBtn2Click(e:MouseEvent ):void/执行取消按钮的相关事件
{
if (zhangHao_text.text != "www" || miMa_text.text != "123")
{
zhangHao_text.text = "";
miMa_text.text = "";
} //所有输入内容清空
}
private function onBtn3Click(e:MouseEvent ):void/执行返回按钮的相关事件
{
fanhui.visible = false;//返回页面不显示
zhangHao_text.text = "";
miMa_text.text = "";//输入内容清空
}
}
}