嗨,我正在尝试在Flash CS3动作脚本上创建一个游戏并在第13-15行继续收到错误,说明内部命名空间中定义_bounces存在冲突,内部命名空间中定义_highscore存在冲突,并且A在内部命名空间中定义_ball存在冲突???请帮忙
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;
public var _vx:Number;
public var _vy:Number;
public function DocumentMain():void
{
_vx = 0;
_vy = 0;
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 stage boundaries for collision
checkBoundaryCollision();
}
private function mouseDownHandler(e:MouseEvent):void
{
//Hit the ball if it has been clicked
}
private function checkBoundaryCollision():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;
}
}
}
}
答案 0 :(得分:0)
转到“高级ActionScript 3.0设置” - 我正在使用CS5.5并且没有CS3(但它应该是相同的)通过文件 - &gt;发布设置 - &gt; ActionScript设置,取消选中“自动声明阶段实例”(这是默认设置)
或者不要在课堂上定义它们。
答案 1 :(得分:0)
可能你有重复的定义。
例如:
var _bounces:TextField;