Actionscript 3 Adobe Flash游戏编程
我正在用Adobe Flash、Javascript 3编写一个球类游戏,在第113行(最后一行)出现一个错误,上面写着: 1087:语法错误:在程序结束后发现额外字符Actionscript 3 Adobe Flash游戏编程,actionscript-3,flash,Actionscript 3,Flash,我正在用Adobe Flash、Javascript 3编写一个球类游戏,在第113行(最后一行)出现一个错误,上面写着: 1087:语法错误:在程序结束后发现额外字符 包 { 导入flash.display.MovieClip 导入flash.text.TextField 导入flash.events.Event 导入flash.events.MouseEvent 公共类DocumentMain扩展了MovieClip { 公共常数:数量=2; 公共常数反弹系数:数字=0.8; 公共变量
包
{
导入flash.display.MovieClip
导入flash.text.TextField
导入flash.events.Event
导入flash.events.MouseEvent
公共类DocumentMain扩展了MovieClip
{
公共常数:数量=2;
公共常数反弹系数:数字=0.8;
公共变量反弹:TextField;
公共变量高分:文本字段;
公共变量球:球;
私有变量vx:编号;
私有变量:数字;
公共函数DocumentMain():void
{
_vx=10;
_vy=0;
_ball.buttonMode=true;
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
}
私有函数enterFrameHandler(e:事件):void
{
//吸引球
_vy+=重力;
//移动球
_ball.x+=\uVx;
_ball.y+=\u vy;
//检查共谋的边界
checkBoundaryCollisions();
}
私有函数mouseDownHandler(e:MouseEvent):void
{
//如果球已被点击,则击球
如果(例如,目标==\u球)
{
命中(e.target.mouseX,e.target.mouseY);
}
}
私有函数checkBoundaryCollisions():void
{
变量左:数字;
右:数字;
var底部:数字;
var top:数字;
左=_ball.x-(_ball.width/2);
右=_ball.x+(_ball.width/2);
底部=_ball.y+(_ball.height/2);
顶部=_ball.y-(_ball.height/2);
如果(左<0&&U vx<0)
{
_ball.x=_ball.width/2;
_vx*=-1;
}
否则,如果(右>stage.stageWidth&&U vx>0)
{
_ball.x=stage.stageWidth-(_ball.width/2);
_vx*=-1;
}
如果(顶部<0&&U vy<0)
{
_ball.y=_ball.height/2;
_vy*=-1;
}
否则如果(底部>舞台高度>0)
{
_ball.y=舞台高度-(_ball.height/2);
_vy*=-反弹系数;
_vx*=反弹系数;
if(Number(_bouncess.text)>Number(_highscore.text))
{
_highscore.text=_bounce.text;
}
_反弹。text=“0”;
}
}
私有函数命中(hitX:Number,hitY:Number):无效
{
//增量反弹
_bounces.text=字符串。(数字(_bounces.text)+1);
//调整球的垂直速度
如果(_vy>0)
{
_vy*=-反弹系数/2;
}
_vy-=撞击力;
//调整球的水平速度
如果(_vx*hitX>0)
{
_vx*=反弹系数;
}
_vx-=(2*击球/球宽)*击球力;
}
}
}
}
去掉最后一个大括号}。文件末尾的内容太多。
我还认为你指的是动作脚本3。我试图去掉}符号,但错误仍然存在:(,但如果你数一数}和{你可以看到还有一个动作脚本,是的,动作脚本3:)不过还是谢谢你:D
package
{
import flash.display.MovieClip
import flash.text.TextField
import flash.events.Event
import flash.events.MouseEvent
public class DocumentMain extends MovieClip
{
public const GRAVITY:Number = 2;
public const BOUNCE_FACTOR:Number = 0.8;
public var _bounces:TextField;
public var _highscore:TextField;
public var _ball:Ball;
private var _vx:Number;
private var _vy:Number;
public function DocumentMain():void
{
_vx = 10;
_vy = 0;
_ball.buttonMode = true;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
}
private function enterFrameHandler(e:Event):void
{
// gravitate the ball
_vy += GRAVITY;
// move the ball
_ball.x += _vx;
_ball.y += _vy;
// check boundaries for collusion
checkBoundaryCollisions();
}
private function mouseDownHandler(e:MouseEvent):void
{
//hit the ball if it has been clicked
if (e.target == _ball)
{
hit(e.target.mouseX, e.target.mouseY);
}
}
private function checkBoundaryCollisions():void
{
var left:Number;
var right:Number;
var bottom:Number;
var top:Number;
left = _ball.x - (_ball.width / 2);
right = _ball.x + (_ball.width / 2);
bottom = _ball.y + (_ball.height / 2);
top = _ball.y - (_ball.height / 2);
if (left < 0 && _vx < 0)
{
_ball.x = _ball.width / 2;
_vx *= -1;
}
else if (right > stage.stageWidth && _vx > 0)
{
_ball.x = stage.stageWidth - (_ball.width / 2);
_vx *= -1;
}
if (top < 0 && _vy < 0)
{
_ball.y = _ball.height / 2;
_vy *= -1;
}
else if (bottom > stage.stageHeight && _vy > 0)
{
_ball.y = stage.stageHeight - (_ball.height / 2);
_vy *= -BOUNCE_FACTOR;
_vx *= BOUNCE_FACTOR;
if (Number(_bounces.text) > Number(_highscore.text))
{
_highscore.text = _bounce.text;
}
_bounces.text = "0";
}
}
private function hit(hitX:Number, hitY:Number):void
{
//increment bounces
_bounces.text = String.(Number(_bounces.text) + 1);
//adjust the vertical velocity of the ball
if (_vy > 0)
{
_vy *= -BOUNCE_FACTOR / 2 ;
}
_vy -= HIT_FORCE;
//adjust the horizontaly velocity of the ball
if (_vx * hitX > 0)
{
_vx *= -BOUNCE_FACTOR;
}
_vx -= ( 2 * hitX / _ball.width) * HIT_FORCE;
}
}
}
}