zoukankan      html  css  js  c++  java
  • 变化的小球

    ==========onBall文档类==========
    
    package {
    	import flash.display.Sprite;
    	import flash.events.Event;
    	import flash.display.StageScaleMode;
    	public class onBall extends Sprite {
    		private var left:uint=43;//黑球的半径为43
    		private var right:uint=458;//舞台宽度-43
    		private var top:uint=43;//黑球的半径为43
    		private var bottom:uint=245;//舞台高度-43
    		public function onBall():void {
    			stage.scaleMode=StageScaleMode.NO_SCALE;
    			//设置即使播放器窗口拉大,舞台大小也不拉伸
    			init();
    			addEventListener(Event.ENTER_FRAME,blackdong);
    		}
    		private function init():void {
    			for (var i:int=0; i<5; i++) {
    				var blackball:Ball=new Ball(0x000000,43);
    				addChildAt(blackball,i);//黑色小球在显示列表的索引号0-5
    			}
    			for (var t:int=0; t<5; t++) {
    				var whiteball:Ball=new Ball(0xffffff,40);
    				whiteball.x=55*(t+1);
    				whiteball.y=143;
    				whiteball.yspeed=t+5;
    				whiteball.xspeed=Math.random()*5+1;
    				addChildAt(whiteball,t+5);//白色小球在显示列表的索引号5-9
    				whiteball.addEventListener(Event.ENTER_FRAME,whitedong);
    			}
    		}
    
    		private function whitedong(evt:Event):void {
    			evt.target.x+=evt.target.xspeed;
    			evt.target.y+=evt.target.yspeed;
    			if (evt.target.x<=left||evt.target.x>=right) {
    				evt.target.xspeed*=-1;
    			}
    			if (evt.target.y<=top||evt.target.y>=bottom) {
    				evt.target.yspeed*=-1;
    			}
    		}
    		private function blackdong(evt:Event):void {
    			for (var h:int=0; h<5; h++) {
    				getChildAt(h).x=getChildAt(h+5).x;
    				getChildAt(h).y=getChildAt(h+5).y;
    			}
    		}
    	}
    }
    
    ==========Ball小球类==========
    
    package {
    	import flash.display.Shape;
    	public class Ball extends Shape {
    		private var _xspeed:int;
    		private var _yspeed:int;
    		//创建小球类,传入2个参数:颜色和半径,这是为了定义2种小球:黑色和白色
    		public function Ball(_color:uint,_r:uint):void {
    			init(_color,_r);
    		}
    		private function init(_color:uint,_r:uint):void {
    			this.graphics.beginFill(_color);
    			this.graphics.drawCircle(0,0,_r);
    			this.graphics.endFill();
    		}
    
    		public function get xspeed():int {
    			return _xspeed;
    		}
    		public function set xspeed(xp:int):void {
    			_xspeed=xp;
    		}
    		public function get yspeed():int {
    			return _yspeed;
    		}
    		public function set yspeed(yp:int):void {
    			_yspeed=yp;
    		}
    	}
    }
    
  • 相关阅读:
    feature.xml和workflow.xml的配置说明
    infopath开发中的疑惑
    winform应用程序呈现infopath表单
    一,EXTJS介绍
    AD中各字段在代码访问时的字段表述及访问AD用户的例子
    start blackberry by proxy
    【转】两个Action 动态传参数
    【转】Eclipse中如何查找所有调用方法a()的类
    JAVA 学习记录
    css 选择器 优先级
  • 原文地址:https://www.cnblogs.com/leon3286/p/1708555.html
Copyright © 2011-2022 走看看