源码:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” verticalAlign=”top” applicationComplete=”init()”>
<mx:Script>
<!–[CDATA[
import mx.events.ItemClickEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
public var dataColl:ArrayCollection=new ArrayCollection();
//ID编号
var k=1;
//联系人对象
var userobj:Object;
//性别默认状态
var sexobj:String=”男”;
//右键删除菜单
var menucont:ContextMenu;
//初始化行数
var p:int=0;
public function init():void{
menucont=new ContextMenu();
addMenuItems();
}
//添加右键菜单项
public function addMenuItems():void{
var item:ContextMenuItem = new ContextMenuItem(“删除”);
menucont.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemHandler);
menucont.hideBuiltInItems();
userdata.contextMenu = menucont;
}
//菜单右键事件处理
public function menuItemHandler(event:ContextMenuEvent):void{
var CaptionString:String=event.target.caption;
if(CaptionString==”删除”){
//确定鼠标所在行数
var findex:Number = Math.floor(userdata.contentMouseY/userdata.rowHeight)-1 + userdata.verticalScrollPosition;
if (findex<0 || findex>=userdata.verticalScrollPosition+userdata.rowCount-1) //行号小于0时和大于datagrid行总数时的 错误处理
{
Alert.show(“请选择要删除的行”,”提示”);
} else {
p=findex;
dataColl.removeItemAt(p);
Alert.show(“删除成功”,”提示”);
}
}
}
public function checkuser(event:MouseEvent):void{
var gname=uname.text;
var gphone=uphone.text;
if(gname!=”” && gphone!=””){
dataprovider();
}else{
Alert.show(“请输入用户名或电话号码”,”提示”);
}
}
//单选按钮触发事件
public function changsex(event:ItemClickEvent):void{
if(event.currentTarget.selectedValue==”f”){
sexobj= “女”;
}else{
sexobj= “男”;
}
}
//重置
public function resetvalue(event:MouseEvent):void{
uname.text=””;
uphone.text=””;
male.selected=true;
}
//创建联系人信息
public function dataprovider():Object{
userobj=new Object();
userobj[“uid”]=k;
userobj[“uname”]=uname.text;
userobj[“uphone”]=uphone.text;
userobj[“usex”]=sexobj;
dataColl.addItem(userobj);
k++;
return userobj;
}
]]–>
</mx:Script>
<mx:Form>
<mx:Text text=”联系簿” fontWeight=”bold” fontSize=”14″ textAlign=”center” width=”233″ color=”#1B78C6″/>
<mx:FormItem label=”姓名” fontSize=”12″ fontWeight=”bold” horizontalAlign=”left”>
<mx:TextInput id=”uname”/>
</mx:FormItem>
<mx:RadioButtonGroup id=”sexgroup” itemClick=”changsex(event)”/>
<mx:FormItem label=”性别” horizontalAlign=”center” fontSize=”12″ fontWeight=”bold”>
<mx:HBox>
<mx:RadioButton id=”male” label=”男性” groupName=”sexgroup” selected=”true” value=”m”/>
<mx:RadioButton id=”female” label=”女性” groupName=”sexgroup” value=”f”/>
</mx:HBox>
</mx:FormItem>
<mx:FormItem label=”电话号码” fontWeight=”bold” fontSize=”12″ horizontalAlign=”center”>
<mx:TextInput id=”uphone”/>
</mx:FormItem>
<mx:HBox width=”232″ height=”35″ verticalAlign=”middle” horizontalAlign=”center”>
<mx:Button id=”go” label=”添加” fontSize=”12″ fontWeight=”normal” click=”checkuser(event)” textAlign=”center” height=”30″ width=”60″/>
<mx:Button id=”reset” label=”重置” fontWeight=”normal” fontSize=”12″ height=”30″ width=”60″ click=”resetvalue(event)”/>
</mx:HBox>
</mx:Form>
<mx:DataGrid dataProvider=”{dataColl}” width=”400″ id=”userdata”
fontSize=”12″ borderStyle=”inset” fontWeight=”bold” textAlign=”center” alternatingItemColors=”[#F1B6B6, #F2EB37]” height=”210″ editable=”true”>
<mx:columns>
<mx:DataGridColumn headerText=”ID” dataField=”uid”/>
<mx:DataGridColumn headerText=”联系人” dataField=”uname”/>
<mx:DataGridColumn headerText=”性别” dataField=”usex”/>
<mx:DataGridColumn headerText=”电话号码” dataField=”uphone”/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
以上就是【flex 简单例子(含实例效果图 源码)】的全部内容了,欢迎留言评论进行交流!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
8. 精力有限,不少源码未能详细测试(解密),不能分辨部分源码是病毒还是误报,所以没有进行任何修改,大家使用前请进行甄别
丞旭猿论坛
暂无评论内容