我认为当我调用 treeGroup 符号时可能会出现问题。As3 不是将其添加到显示列表中吗?我得到了从 adobe 加载外部 swf 文件的代码。他们确实有不止一种方法,所以我可能使用了错误的方法。正在加载的外部文件会引发您在屏幕截图中看到的错误。代码也在那里。该文件运行良好,没有错误,当我在另一个文件中加载 swf 时,它列出了错误。我还可以查看和更改加载电影的 X 和 Y 位置,但它没有运行。所以它已加载,但在我看来,添加到显示列表可能存在问题,或者可能导致我使用 MovieClip(root),因为第 12 行是我第一次使用它的地方。我必须这样做,因为我需要使用 setChildIndex。
主电影是游戏的主菜单。我要加载的另一个文件是我正在制作的高尔夫游戏的第一个洞。
这是 adobe 的链接,我使用了他们列出的第一种方法。https://helpx.adobe.com/flash/kb/load-external-swf-swf.html
如果您需要更多信息,我可以提供这两个 swf 文件的所有代码。
错误代码是 ArgumentError:错误 #2005:参数 0 的类型不正确。应该是类型 BitmapData。在 Flash.display::BitmapData/hitTest() 在 Hole1_fla::Symbol2_1/treeDetect()[Hole1_fla.Symbol2_1::frame1:12]
这就是我加载 swf 的方式。
var myLoader:Loader = new Loader(); // create a new instance of the Loader class
var url:URLRequest = new URLRequest("Hole1.swf"); // in this case both SWFs are in the same folder
myLoader.load(url);
我认为符号中的代码是问题所在。
var tree1:treeGroup = new treeGroup();
addChild(tree1);
setChildIndex(tree1,15);
var tree1Rect:Rectangle = tree1.getBounds(this);
var tree1ClipBmpData = new BitmapData(tree1Rect.width, tree1Rect.height, true, 0);
tree1ClipBmpData.draw(tree1);
addEventListener(Event.ENTER_FRAME,treeDetect);
function treeDetect(event:Event) {
// code for trees to detect if we hit some trees
if (tree1ClipBmpData.hitTest(new Point(tree1.x, tree1.y),255,MovieClip(root).ballClipBmpData,new Point(MovieClip(root).backhole1.golfball.x, MovieClip(root).backhole1.golfball.y),255)) { // this is line 12 poping the error in the symbol that is in the swf im loading in.
if (MovieClip(root).backhole1.golfball.scaleX == .1 && MovieClip(root).backhole1.golfball.scaleY == .1) {
setChildIndex(tree1,17);
if (MovieClip(root).backhole1.golfball.scaleX >= .3 && MovieClip(root).backhole1.golfball.scaleY >= .3) {
MovieClip(root).friction = .05;
}
}
if (MovieClip(root).backhole1.golfball.scaleX <= .3 && MovieClip(root).backhole1.golfball.scaleY <= .3) {
if (MovieClip(root).goingDown == 1) {
MovieClip(root).friction = .08;
setChildIndex(tree1,17);
MovieClip(root).backhole1.golfball.scaleX = .1;
MovieClip(root).backhole1.golfball.scaleY = .1;
MovieClip(root).goingDown = 0;
}
}
} else {
setChildIndex(tree1,15);
}
}
第一个 MovieClip(root) 在 hitTest 中的位置是第 12 行,它弹出错误消息并且每帧都发生。