接了一个ssc的小项目,却因为对方的不作答而半途而废。我写了一天的代码算是废了。
主程序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" width="600" height="950" xmlns:cc="*"> <mx:Script> <![CDATA[ import com.adobe.serialization.json.JSON; import mx.controls.Alert; import mx.formatters.DateFormatter; [Bindable] public var t1:int; [Bindable] public var t2:int; [Bindable] public var t3:int; [Bindable] public var t4:int; [Bindable] public var now:Date; [Bindable] public var balls:Array = []; public static var INTERVAL:int = 10*60; public static var BALL_COUNT:int = 11; public var count:int; public function init():void { now = new Date(); var timer:Timer = new Timer(1000); timer.addEventListener(TimerEvent.TIMER, onTimer); timer.start(); var ss:String = JSON.encode(null); //getBalls(); var obj:Object = {}; obj.a = 123; obj.b = "asdf"; Alert.show(obj+""); var xx:XML = <asfasf/> xx.appendChild(obj); Alert.show(xx.toXMLString()); } public function getBalls():void { var center:Point = new Point(ballbox.width/2, ballbox.height/2-50); var radis:Number = ballbox.width/2 - 120; trace(radis + " / " + ballbox.width/2); for(var i:int=1;i<=BALL_COUNT;i++) { balls[i] = (int)(Math.random()*100); trace(balls[i]); var btn:Button = new Button(); btn.width = 30; btn.height = 30; btn.setStyle("cornerRadius", 30); btn.label = balls[i]+""; btn.x = radis*Math.sin(360*i/(BALL_COUNT-1)) + center.x; btn.y = radis*Math.cos(360*i/(BALL_COUNT-1)) + center.y; ballbox.addChild(btn); trace("" + btn.x + " / " + btn.y); } } public function onTimer(e:TimerEvent):void { count ++; if(count == INTERVAL) { count = 0; t1 = 1; t2 = 0; t1 = 0; t2 = 0; // lottery Alert.show("开奖了!"); } var left:int = INTERVAL - count; var minutes:int = left/60; var seconds:int = left%60; if(minutes>=10) { t1 = 1; t2 = 0; } else { t1 = 0; t2 = minutes; } if(seconds>=10) { t3 = seconds/10; t4 = seconds%10; } else { t3 = 0; t4 = seconds; } } ]]> </mx:Script> <mx:Panel title="欢迎光临本店" width="100%" height="100%"> <mx:Button color="red" label="233234"/> <mx:HBox horizontalAlign="right" width="100%"> <mx:Text text="距离本期销售截止,还有"/> <mx:Button id="n1" label="{t1}" fontSize="20" fontWeight="bold"/> <mx:Button id="n2" label="{t2}" fontSize="20" fontWeight="bold"/> <mx:Text text="分"/> <mx:Button id="n3" label="{t3}" fontSize="20" fontWeight="bold"/> <mx:Button id="n4" label="{t4}" fontSize="20" fontWeight="bold"/> <mx:Text text="秒"/> </mx:HBox> <mx:Canvas id="ballbox" height="100%" width="100%"> </mx:Canvas> </mx:Panel> <mx:HBox x="100" y="100" horizontalGap="2"> <cc:RollableBall2 cW="80" cH="50"/> <cc:RollableBall2 cW="80" cH="50"/> <cc:RollableBall2 cW="80" cH="50"/> <cc:RollableBall2 cW="80" cH="50"/> <cc:RollableBall2 cW="80" cH="50"/> </mx:HBox> <mx:HBox x="100" y="300" horizontalGap="2"> <cc:RollableBall3 cW="80" cH="50"/> <cc:RollableBall3 cW="80" cH="50"/> <cc:RollableBall3 cW="80" cH="50"/> <cc:RollableBall3 cW="80" cH="50"/> <cc:RollableBall3 cW="80" cH="50"/> </mx:HBox> </mx:Application>
按钮控件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="{this.cW}" height="{this.cH}" creationComplete="init()" horizontalScrollPolicy="off" verticalScrollPolicy="off" fontSize="{this.cW/3}" fontWeight="bold" fontThickness="{this.cW/20}" borderThickness="2" borderColor="blue" borderStyle="outset"> <mx:Script> <![CDATA[ import flash.utils.setTimeout; import mx.controls.Button; public var TOTAL_INTERVAL:int = 5*1000; public var interval:int = 5; public static var ROLL_COUNT:int = 100; public var count:int = 0; public var ecliipsedTime:int = 0; public var y1:int = 0; public var y2:int = -100; public var btn1:Button = new Button(); public var btn2:Button = new Button(); [Bindable] public var cW:int; [Bindable] public var cH:int; public function init():void { btn1.label = (int)(Math.random()*10); btn1.width = cW; btn1.height = cH; //btn1.setStyle("fontSize", 20); btn2.label = (int)(Math.random()*10); btn2.width = cW; btn2.height = cH; btn2.y = -cH; //btn2.setStyle("fontSize", 20); this.addChild(btn1); this.addChild(btn2); start(); } public function start():void { var delay:int = (int)(Math.random()*1000); var t:Timer = new Timer(delay, 1); t.addEventListener(TimerEvent.TIMER, doStart); t.start(); } public function doStart(e:TimerEvent):void { goTimer(); } public function goTimer():void { flash.utils.setTimeout(function():void{ //Alert.show("sleep test ok"); onTimer(); },interval,null); } public function newBtn():Button { return null; } // 开始滚动的时候要慢, 快要停止id时候也要慢! public function onTimer():void { ecliipsedTime += interval; count ++; if(count>=ROLL_COUNT*9/10) { interval += Math.random()*100; } // if(count>=ROLL_COUNT*9/10) { // interval += 100; // } // if(count>=ROLL_COUNT*29/30) { // interval += 200; // } // if(count>=ROLL_COUNT*49/50) { // interval += 500; // } // if(TOTAL_INTERVAL-ecliipsedTime<=1) { // interval += 20; // } if(count>ROLL_COUNT) { return; } y1 += 10; if(y1>=cH) { y1 = -100; btn1.label = (int)(Math.random()*10); } btn1.y = y1; y2 += 10; if(y2>=cH) { y2 = -100; btn2.label = (int)(Math.random()*10); } btn2.y = y2; goTimer(); } ]]> </mx:Script> </mx:Canvas>
按钮控件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="{this.cW}" height="{this.cH*3}" creationComplete="init()" horizontalScrollPolicy="off" verticalScrollPolicy="off" fontSize="{this.cW/3}" fontWeight="normal" fontThickness="{this.cW/20}" borderThickness="2" borderColor="blue" borderStyle="outset"> <mx:Script> <![CDATA[ import flash.utils.setTimeout; import mx.controls.Button; public var TOTAL_INTERVAL:int = 5*1000; public var interval:int = 5; public static var ROLL_COUNT:int = 100; public var count:int = 0; public var ecliipsedTime:int = 0; public var y1:int; public var y2:int; public var y3:int; public var y4:int; public var btn1:Button = new Button(); public var btn2:Button = new Button(); public var btn3:Button = new Button(); public var btn4:Button = new Button(); [Bindable] public var cW:int;// button 宽度 [Bindable] public var cH:int;// button 高度 public function init():void { y1 = 0; y2 = cH*1; y3 = cH*2; y4 = -cH; btn1.label = (int)(Math.random()*10); btn1.width = cW; btn1.height = cH; btn1.y = y1; //btn1.setStyle("fontSize", 20); this.addChild(btn1); btn2.label = (int)(Math.random()*10); btn2.width = cW; btn2.height = cH; btn2.y = y2; this.addChild(btn2); btn3.label = (int)(Math.random()*10); btn3.width = cW; btn3.height = cH; btn3.y = y3; this.addChild(btn3); btn4.label = (int)(Math.random()*10); btn4.width = cW; btn4.height = cH; btn4.y = y4; this.addChild(btn4); start(); } public function start():void { var delay:int = (int)(Math.random()*2000); var t:Timer = new Timer(delay, 1); t.addEventListener(TimerEvent.TIMER, doStart); t.start(); } public function doStart(e:TimerEvent):void { goTimer(); } public function goTimer():void { flash.utils.setTimeout(function():void{ //Alert.show("sleep test ok"); onTimer(); },interval,null); } public function newBtn():Button { return null; } public function onTimer():void { ecliipsedTime += interval; count ++; // if(count>=ROLL_COUNT*9/10) { // interval += Math.random()*100; // } // if(count>=ROLL_COUNT*9/10) { // interval += 100; // } // if(count>=ROLL_COUNT*29/30) { // interval += 200; // } // if(count>=ROLL_COUNT*49/50) { // interval += 500; // } // if(TOTAL_INTERVAL-ecliipsedTime<=1) { // interval += 20; // } if(count>ROLL_COUNT) { btn2.setStyle("fontWight", "bold"); btn2.setStyle("fontSize", this.cW/2); btn2.setStyle("color", "red"); btn2.setStyle("fontThickness", this.cW/10); btn2.invalidateProperties(); btn2.invalidateSize(); btn2.invalidateDisplayList(); return; } y1 += 10; if(y1>=cH*3) { y1 = -cH; btn1.label = (int)(Math.random()*10); } btn1.y = y1; y2 += 10; if(y2>=cH*3) { y2 = -cH; btn2.label = (int)(Math.random()*10); } btn2.y = y2; y3 += 10; if(y3>=cH*3) { y3 = -cH; btn3.label = (int)(Math.random()*10); } btn3.y = y3; y4 += 10; if(y4>=cH*3) { y4 = -cH; btn4.label = (int)(Math.random()*10); } btn4.y = y4; goTimer(); } ]]> </mx:Script> </mx:Canvas>