原文地址:http://www.lxlong.net/?p=1793
- var oldX:Number = ball_mc.x;
- var oldY:Number = ball_mc.y;
- var v:Number;
- var g:Number;
- var time:Number;
- var visi:Boolean = true;
- var b:Boolean;
- var drawSp:Shape=new Shape();
- var xArr:Array = [];
- var yArr:Array = [];
- var ind:uint;
- addChild(drawSp);
- for (var i:int=0; i<=30; i++) {
- graphics.lineStyle(0,0xcccccc);
- if (i % 5 == 0) {
- graphics.lineStyle(0,0×000000);
- }
- graphics.moveTo(100+i*20,50);
- graphics.lineTo(100+i*20,50+30*20);
- graphics.moveTo(100,50+i*20);
- graphics.lineTo(100+30*20,50+i*20);
- }
- start_btn.addEventListener(MouseEvent.CLICK,startFunc);
- function startFunc(e) {
- addEventListener(Event.ENTER_FRAME,onFrame);
- b = true;
- xball_mc.x = ball_mc.x = oldX;
- yball_mc.y = ball_mc.y = oldY;
- v = Number(input_txt.text);
- g = 1.5;
- time = 0;
- xArr = [];
- yArr = [];
- drawCircle(ball_mc.x,ball_mc.y);//每次先在起点处画个点
- xArr[0]=100;
- yArr[0]=50;//每次把这个位置预先放入坐标数组的首位
- }
- function onFrame(e) {
- time++;
- time_txt.text=(Math.round(time*10)/100).toString();
- ball_mc.x =100+ v * (time );
- ball_mc.y += g * (time / 10) * (time / 10) / 2/3.3;
- xball_mc.x =100+ v * (time )
- yball_mc.y += g * (time / 10 )*( time / 10) / 2/3.3;
- if (time >= 100) {
- removeEventListener(Event.ENTER_FRAME,onFrame);
- b = false;
- }
- drawCircle(ball_mc.x,ball_mc.y);
- xArr.push(ball_mc.x);
- yArr.push(ball_mc.y);
- ind = xArr.length;
- }
- function drawCircle(xx:Number,yy:Number) {
- drawSp.graphics.beginFill(0×000000);
- drawSp.graphics.drawCircle(xx,yy,1);
- }
- reset_btn.addEventListener(MouseEvent.CLICK,reset);
- function reset(e) {
- xball_mc.x = ball_mc.x = oldX;
- yball_mc.y = ball_mc.y = oldY;
- removeEventListener(Event.ENTER_FRAME,onFrame);
- }
- prev_btn.addEventListener(MouseEvent.CLICK,prev);
- function prev(e) {
- if (! b) {
- ind > 5 ? ind -= 5:ind = 0;
- xball_mc.x = ball_mc.x = xArr[ind];
- yball_mc.y = ball_mc.y = yArr[ind];
- }
- }
- next_btn.addEventListener(MouseEvent.CLICK,nextF);
- function nextF(e) {
- if (! b) {
- ind < xArr.length – 6 ? ind += 5:ind = xArr.length – 1;
- xball_mc.x = ball_mc.x = xArr[ind];
- yball_mc.y = ball_mc.y = yArr[ind];
- }
- }
- clear_btn.addEventListener(MouseEvent.CLICK,clearFunc);
- function clearFunc(e) {
- drawSp.graphics.clear();
- }
- visible_btn.addEventListener(MouseEvent.CLICK,visibleFunc);
- function visibleFunc(e) {
- xball_mc.visible = ! xball_mc.visible;
- yball_mc.visible = ! yball_mc.visible;
- (visi=!visi) ? visible_btn.alpha =1:visible_btn.alpha = 0.5;
- }
复制代码
paoWuYunDong.swf
(8 KB, 下载次数: 15)
|