我使用的是在stackoverflow.com上的另一个页面中找到的一段代码
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class Guest extends MovieClip
{
var walkSpeed:Number = 5;
var oldPosX;
var oldPosY;
public function Guest()
{
stage.addEventListener(MouseEvent.CLICK, walk);
}
function walk(event: MouseEvent):void
{
oldPosX = parent.mouseX;
oldPosY = parent.mouseY;
rotation = Math.atan2(oldPosY - y, oldPosX - x) / Math.PI * 180;
addEventListener(Event.ENTER_FRAME, loop);
}
function loop(event: Event):void
{
// see if you're near the target
var dx:Number = oldPosX - x;
var dy:Number = oldPosY - y;
var distance: Number = Math.sqrt((dx * dx) + (dy * dy));
if (distance < walkSpeed)
{
// if you are near the target, snap to it
x = oldPosX;
y = oldPosY;
removeEventListener(Event.ENTER_FRAME, loop);
}
else
{
x = x + Math.cos(rotation / 180 * Math.PI) * walkSpeed;
y = y + Math.sin(rotation / 180 * Math.PI) * walkSpeed;
}
}
}
}
此特定行(第2行)发生错误:
import flash.display.MovieClip;
我认为我的案例是独一无二的,因为当我查阅时,人们会说这是一个命名冲突。你有什么想法吗?