在场景中做一小球按F8设为按钮 回到主场景再次按F8,在按钮中写as: on (press) { dragging = true; startDrag (this, true); } on (release, releaseOutside) { dragging = false; stopDrag ();} 在第一帧写as: movheight = 380; mvwidth =550; 在mc中写as:
onClipEvent (load) { gravity = 9;//重力加速度 bounce = 0.8;//反弹是原来的8/10 radius = this._width/2;//小球半径(用来判断小球反弹的位置) } onClipEvent (enterFrame) { //每一帧都执行一次 oldx = x;//旧的小球x坐标(第一次运行时不被执行) oldy = y;//旧的小球y坐标 x = this._x;//小球x坐标 y = this._y;//小球y坐标 if (dragging) {//判断是否按下鼠标 vx = (x-oldx)*10;//小球现在x坐标减上一次的x坐标得出运动的距离,再扩大十倍 vy = (y-oldy)*10;//小球现在y坐标减上一次的y坐标得出运动的距离,再扩大十倍 } else {//释放时 vy += gravity;//vy加重力加速度赋给vy x += (vx/10);//返回原来的x值 y += (vy/10);//返回原来的y值 if (y<radius) {//判断是不是到达上边 y = radius;//小球的y坐标等于小球半径值的y坐标 vx *= bounce;//乘以反弹值 vy *= -bounce; } if (y>(_root.movheight-radius)) {//判断是不是到达底边 y = _root.movheight-radius; vx *= bounce; vy *= -bounce;(同上) } if (x<radius) {//判断是不是到达左边 x = radius; vx *= -bounce; vy *= bounce; } if (x>(_root.movwidth-radius)) {//判断是不是到达右边 x = _root.movwidth-radius; vx *= -bounce; vy *= bounce; } setProperty (this, _x, x);//把变量x赋给小球 setProperty (this, _y, y);//把变量y赋给小球 }
|