checkbox.mxml
<?xml version="1.0" encoding="utf-8"?>
<!--http://blog.csdn.net/lionFromAsia/archive/2008/11/27/3393067.aspx-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onInit()" xmlns="*" fontSize="14" layout="absolute" backgroundGradientColors="[#ffffff, #c0c0c0]">
<mx:Script>
<![CDATA[
public function onInit():void
{
userRequest.send();
}
import mx.controls.Alert; //引入Alert完整组件类
import mx.events.CloseEvent;
private function alertPopup(event:Event):void{
if(userid.text!=""){
Alert.okLabel="确定"; //修改OK按钮上的文字
Alert.cancelLabel="取消"; //修改Cancel按钮上的文字
//调用Alert.show()弹出对话框,对话框上有确定和取消按钮
//Alert.show("您确定要删除吗?", "警告", 3, this, alertClickHandler);
Alert.show("您确定要删除吗?", "警告", Alert.OK|Alert.CANCEL, this, alertClickHandler);
}
else{
Alert.okLabel="确定"; //修改OK按钮上的文字
//调用Alert.show()弹出对话框,对话框上有确定和取消按钮
Alert.show("请选择要删除的记录!!","警告",Alert.OK);
}
}
private function alertClickHandler(event:CloseEvent):void {
if (event.detail==Alert.OK){
userRequest.send();
showAndHide(1000);
}
else{
}
}
import mx.controls.Alert;
import mx.managers.PopUpManager;
private var alert:Alert;
private function showAndHide(delay:Number):void {
var alertText:String = "成功删除!";
var alertTitle:String = "恭喜";
alert = Alert.show(alertText, alertTitle);
setTimeout(hideAlert, delay);
}
private function hideAlert():void {
PopUpManager.removePopUp(alert);
}
]]>
</mx:Script>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function doShow():void
{
// var strCountry:String="";
// if (checkBox1.selected)
// strCountry+=checkBox1.label;
// if (checkBox2.selected)
// strCountry+=" " +checkBox2.label;
// if (checkBox3.selected)
// strCountry+=" " +checkBox3.label;
// Alert.show("您选择的国家有:"+strCountry);
countryname.text="";
if (checkBox1.selected)
countryname.text+=checkBox1.label;
if (checkBox2.selected)
countryname.text+=" " +checkBox2.label;
if (checkBox3.selected)
countryname.text+=" " +checkBox3.label;
Alert.show("您选择的国家有:"+countryname.text);
}
public function add():void
{
countryname.text="";
if (checkBox1.selected)
countryname.text+=checkBox1.label;
if (checkBox2.selected)
countryname.text+=" " +checkBox2.label;
if (checkBox3.selected)
countryname.text+=" " +checkBox3.label;
if(countryname.text==""){
Alert.show("请选择填项!!","警告",Alert.OK);
}
else{
useredit.send();
Alert.show("添加成功!!","警告",Alert.OK);
userRequest.send();
}
}
]]>
</mx:Script>
<mx:Label id="label1" text="Datagrid实例一" x="74" y="25" fontSize="20"></mx:Label>
<mx:HTTPService id="useredit" url="datagrid.php" useProxy="false" method="POST">
<mx:request xmlns="">
<countryname>{countryname.text}</countryname>
</mx:request>
</mx:HTTPService>
<mx:HTTPService id="userRequest" url="datagrid.php" useProxy="false" method="POST">
<mx:request xmlns="">
<userid>{userid.text}</userid>
</mx:request>
</mx:HTTPService>
<mx:DataGrid id="dgUserRequest" x="74" y="64" dataProvider="{userRequest.lastResult.users.user}" width="581" textAlign="center" height="212">
<mx:columns>
<mx:DataGridColumn headerText="用户ID" dataField="userid"/>
<mx:DataGridColumn headerText="用户名" dataField="username"/>
<mx:DataGridColumn headerText="Email" dataField="emailaddress"/>
</mx:columns>
</mx:DataGrid>
<mx:Button label="删除" click="alertPopup(event)" x="74" y="293"/>
<mx:TextInput x="230" y="102" id="userid" text="{dgUserRequest.selectedItem.userid}" visible="false" width="48"/>
<mx:Panel width="396" height="261" layout="absolute" borderStyle="inset" backgroundColor="#EA6F0B" borderColor="#F50E0E" horizontalCenter="128" verticalCenter="120">
<mx:CheckBox x="116" y="22" label="China" color="#0A20F8" fontSize="16" fontWeight="bold" id="checkBox1"/>
<mx:CheckBox x="116" y="58" label="England" color="#0A20F8" fontSize="16" fontWeight="bold" id="checkBox2"/>
<mx:CheckBox x="116" y="94" label="USA" color="#0A20F8" fontSize="16" fontWeight="bold" id="checkBox3"/>
<mx:Label id="countryname" text="" x="27" y="0" width="221" visible="true">
</mx:Label>
<!--<mx:Button x="108" y="152" label="Show" click="doShow()" color="#0A15F8"/>-->
<mx:Button x="191" y="152" label="Add" click="add()" color="#0A15F8"/>
</mx:Panel>
</mx:Application>