1,弹出的按钮
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" width="254" height="296" backgroundColor="#E7E6E6" fontSize="12" borderStyle="outset" borderColor="#E0DEDE" label="canvasBG" cornerRadius="20">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.managers.PopUpManager;
import mx.controls.Alert;
[Bindable]
public var value_choose_hour:int=0;
[Bindable]
public var value_choose_minute:int=0;
[Bindable]
public var app_index:int=0;
[Bindable]
public var mainApp:h4=null;
private function init():void
{
bulidButton(app_index);
}
/* private function bindIndex():void
{
app_index=mainApp.bindIndex;
} */
private function closePop():void
{
PopUpManager.removePopUp(this);
}
private function bulidButton(index:int):void
{
var i:int,x:int=0,y:int=0;
for(i=0;i<index;i++)
{
var bt:Button=creatButton(i.toString(),index);//设置位置
bt.width=45;//一行可以放6个button
bt.height=30;
bt.x=x;
bt.y=y;
x=x+45;
if((i+1)%5==0)
{
x=0;
y=y+30;
}
//y=y+4;
canvas1.addChild(bt);
}
}
private function creatButton(label:String,check:int):Button
{
var bt:Button=new Button();
bt.label=label;
bt.id="bt"+label;
bt.addEventListener(MouseEvent.CLICK,btClick);
function btClick(event:MouseEvent):void
{
if(check>24)
{
value_choose_minute=int(bt.label);
}
else
{
value_choose_hour=int(bt.label);
}
closePop();
}
return bt;
}
]]>
</mx:Script>
<mx:Canvas x="0" y="-1" width="100%" height="100%" id="canvas1" backgroundColor="#FFFFFF" cornerRadius="20">
</mx:Canvas>
</mx:Canvas>
2:time 组件
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="white"
creationComplete="init()"
width="222" height="26" >
<mx:Script>
<![CDATA[
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import mx.controls.Alert;
private function init():void
{
}
private var point1:Point = new Point();
private var point2:Point=new Point();
[Bindable]
private var win_pop_hour:popButton=new popButton();
[Bindable]
private var win_pop_minute:popButton=new popButton();
// [Bindable]
private var hours:String="00";
// [Bindable]
private var minute:String="00";
[Bindable]
public var times:String=hours+":"+minute;
private function NumClickHour():void
{
win_pop_hour=popButton(PopUpManager.createPopUp(this,popButton,false));
point1.x=NumHour.x;
point1.y=NumHour.y;
point1=NumHour.localToGlobal(point1);
win_pop_hour.x=point1.x;
win_pop_hour.y=point1.y;
win_pop_hour.app_index=24;//显示的个数
win_pop_hour.width=230;
win_pop_hour.height=160;
}
private function closePop():void
{
PopUpManager.removePopUp(win_pop_hour);
}
private function NumClickMinute():void
{
win_pop_minute=popButton(PopUpManager.createPopUp(this,popButton,false));
// point2.x=NumMinute.x;
// point2.y=NumMinute.y;
point2.x=0;
point2.y=0;
point2=NumMinute.localToGlobal(point2);
win_pop_minute.x=point2.x+15;
win_pop_minute.y=point2.y+10;
win_pop_minute.app_index=60;
}
private function mySetterBinding(event:FlexEvent,labelTime:Label):void
{
var watcherSetter:ChangeWatcher = BindingUtils.bindSetter(setMyString, labelTime, "text");
function setMyString(v:String):void
{
if(labelTime.id=="labelTimeHour")
{
if(int(v)<10)
{
hours="0"+v;
}
else
{
hours=v;
}
}
else
{
if(int(v)<10)
{
minute="0"+v;
}
else
{
minute=v;
}
}
times=hours+":"+minute;
}
}
private function HourSetterBinding(event:FlexEvent):void
{
mySetterBinding(event,labelTimeHour);
}
private function MinuteSetterBinding(event:FlexEvent):void
{
mySetterBinding(event,labelTimeMinute);
}
]]>
</mx:Script>
<mx:NumericStepper click="NumClickHour()" value="{win_pop_hour.value_choose_hour}" x="41" y="2" id="NumHour" minimum="0" maximum="23"/>
<mx:NumericStepper id="NumMinute" click="NumClickMinute()" value="{win_pop_minute.value_choose_minute}" x="157" y="2" minimum="0" maximum="59"/>
<mx:Label id="labelHour" x="7" y="4" text="hour"/>
<mx:Label id="labelMinute" x="109" y="4" text="minute"/>
<mx:Label visible="false" id="labelTimeHour" initialize="HourSetterBinding(event)" text="{NumHour.value.toString()}"/>
<mx:Label visible="false" id="labelTimeMinute" initialize="MinuteSetterBinding(event)" text="{NumMinute.value.toString()}"/>
</mx:Canvas>
3:使用方法,time属性得到时间
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function btClick():void
{
Alert.show(h4s.times);
}
]]>
</mx:Script>
<ns1:h4 id="h4s" x="74" y="153">
</ns1:h4>
<mx:DateField x="117" y="59"/>
<mx:Label x="423" y="144" text="{h4s.times}"/>
<mx:Label x="444" y="170"/>
<mx:Button x="169" y="254" label="Button" click="btClick()"/>
</mx:Application>
http://www.kaifazu.com
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()" width="254" height="296" backgroundColor="#E7E6E6" fontSize="12" borderStyle="outset" borderColor="#E0DEDE" label="canvasBG" cornerRadius="20">
<mx:Script>
<![CDATA[
import mx.controls.Button;
import mx.managers.PopUpManager;
import mx.controls.Alert;
[Bindable]
public var value_choose_hour:int=0;
[Bindable]
public var value_choose_minute:int=0;
[Bindable]
public var app_index:int=0;
[Bindable]
public var mainApp:h4=null;
private function init():void
{
bulidButton(app_index);
}
/* private function bindIndex():void
{
app_index=mainApp.bindIndex;
} */
private function closePop():void
{
PopUpManager.removePopUp(this);
}
private function bulidButton(index:int):void
{
var i:int,x:int=0,y:int=0;
for(i=0;i<index;i++)
{
var bt:Button=creatButton(i.toString(),index);//设置位置
bt.width=45;//一行可以放6个button
bt.height=30;
bt.x=x;
bt.y=y;
x=x+45;
if((i+1)%5==0)
{
x=0;
y=y+30;
}
//y=y+4;
canvas1.addChild(bt);
}
}
private function creatButton(label:String,check:int):Button
{
var bt:Button=new Button();
bt.label=label;
bt.id="bt"+label;
bt.addEventListener(MouseEvent.CLICK,btClick);
function btClick(event:MouseEvent):void
{
if(check>24)
{
value_choose_minute=int(bt.label);
}
else
{
value_choose_hour=int(bt.label);
}
closePop();
}
return bt;
}
]]>
</mx:Script>
<mx:Canvas x="0" y="-1" width="100%" height="100%" id="canvas1" backgroundColor="#FFFFFF" cornerRadius="20">
</mx:Canvas>
</mx:Canvas>
2:time 组件
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="white"
creationComplete="init()"
width="222" height="26" >
<mx:Script>
<![CDATA[
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import mx.controls.Alert;
private function init():void
{
}
private var point1:Point = new Point();
private var point2:Point=new Point();
[Bindable]
private var win_pop_hour:popButton=new popButton();
[Bindable]
private var win_pop_minute:popButton=new popButton();
// [Bindable]
private var hours:String="00";
// [Bindable]
private var minute:String="00";
[Bindable]
public var times:String=hours+":"+minute;
private function NumClickHour():void
{
win_pop_hour=popButton(PopUpManager.createPopUp(this,popButton,false));
point1.x=NumHour.x;
point1.y=NumHour.y;
point1=NumHour.localToGlobal(point1);
win_pop_hour.x=point1.x;
win_pop_hour.y=point1.y;
win_pop_hour.app_index=24;//显示的个数
win_pop_hour.width=230;
win_pop_hour.height=160;
}
private function closePop():void
{
PopUpManager.removePopUp(win_pop_hour);
}
private function NumClickMinute():void
{
win_pop_minute=popButton(PopUpManager.createPopUp(this,popButton,false));
// point2.x=NumMinute.x;
// point2.y=NumMinute.y;
point2.x=0;
point2.y=0;
point2=NumMinute.localToGlobal(point2);
win_pop_minute.x=point2.x+15;
win_pop_minute.y=point2.y+10;
win_pop_minute.app_index=60;
}
private function mySetterBinding(event:FlexEvent,labelTime:Label):void
{
var watcherSetter:ChangeWatcher = BindingUtils.bindSetter(setMyString, labelTime, "text");
function setMyString(v:String):void
{
if(labelTime.id=="labelTimeHour")
{
if(int(v)<10)
{
hours="0"+v;
}
else
{
hours=v;
}
}
else
{
if(int(v)<10)
{
minute="0"+v;
}
else
{
minute=v;
}
}
times=hours+":"+minute;
}
}
private function HourSetterBinding(event:FlexEvent):void
{
mySetterBinding(event,labelTimeHour);
}
private function MinuteSetterBinding(event:FlexEvent):void
{
mySetterBinding(event,labelTimeMinute);
}
]]>
</mx:Script>
<mx:NumericStepper click="NumClickHour()" value="{win_pop_hour.value_choose_hour}" x="41" y="2" id="NumHour" minimum="0" maximum="23"/>
<mx:NumericStepper id="NumMinute" click="NumClickMinute()" value="{win_pop_minute.value_choose_minute}" x="157" y="2" minimum="0" maximum="59"/>
<mx:Label id="labelHour" x="7" y="4" text="hour"/>
<mx:Label id="labelMinute" x="109" y="4" text="minute"/>
<mx:Label visible="false" id="labelTimeHour" initialize="HourSetterBinding(event)" text="{NumHour.value.toString()}"/>
<mx:Label visible="false" id="labelTimeMinute" initialize="MinuteSetterBinding(event)" text="{NumMinute.value.toString()}"/>
</mx:Canvas>
3:使用方法,time属性得到时间
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="*">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function btClick():void
{
Alert.show(h4s.times);
}
]]>
</mx:Script>
<ns1:h4 id="h4s" x="74" y="153">
</ns1:h4>
<mx:DateField x="117" y="59"/>
<mx:Label x="423" y="144" text="{h4s.times}"/>
<mx:Label x="444" y="170"/>
<mx:Button x="169" y="254" label="Button" click="btClick()"/>
</mx:Application>
http://www.kaifazu.com