我已经到处寻找有这个问题的其他人,似乎无法找到解决方案,所以在这里。
我在教科书中找到了关于益智游戏的Flash CS3教程。这很简单,如果你拿一块它叫做startDrag和stopDrag。
所以我开始制作自己的游戏并在其中创建了一个名为puzzleGame的movieClip。我几乎已经将原始教程中的代码复制到了我的puzzleGame movieClip中,但是当我测试它时,我总是得到一个错误,说startDrag和stopDrag不是一个函数。它与我的主舞台里面的动画片段有关。
如果我将代码更改为this.startDrag,那么它实际上会拖动整个帧。我认为无论出于何种原因,它都没有深入到实际物体中我拖动而只是看到我触摸了动画片本身。
这有意义吗?
这是我的第2帧代码。
stop();
import flash.utils.*;
var mySound:Sound = new correctSound();
var score:Number = 0;
var numClips:Number = 7;
var myClip = new Array(numClips);
myClip[0] = addChild(new a0());
myClip[1] = addChild(new a1());
myClip[2] = addChild(new a2());
myClip[3] = addChild(new a3());
myClip[4] = addChild(new a4());
myClip[5] = addChild(new a5());
myClip[6] = addChild(new a6());
//myClip[7] = addChild(new a7());
//myClip[8] = addChild(new a8());
//myClip[9] = addChild(new a9());
myClip[0].name = "piece0";
myClip[1].name = "piece1";
myClip[2].name = "piece2";
myClip[3].name = "piece3";
myClip[4].name = "piece4";
myClip[5].name = "piece5";
myClip[6].name = "piece6";
//myClip[7].name = "piece7";
//myClip[8].name = "piece8";
//myClip[9].name = "piece9";
var nph = new Array(numClips);
nph[0] = nph0_mc;
nph[1] = nph1_mc;
nph[2] = nph2_mc;
nph[3] = nph3_mc;
nph[4] = nph4_mc;
nph[5] = nph5_mc;
nph[6] = nph6_mc;
//nph[7] = nph7_mc;
//nph[8] = nph8_mc;
//nph[9] = nph9_mc;
var tpg = new Array(numClips);
tpg[0] = tpg0_mc;
tpg[1] = tpg1_mc;
tpg[2] = tpg2_mc;
tpg[3] = tpg3_mc;
tpg[4] = tpg4_mc;
tpg[5] = tpg5_mc;
tpg[6] = tpg6_mc;
//tpg[7] = tpg7_mc;
//tpg[8] = tpg8_mc;
//tpg[9] = tpg9_mc;
var x0 = myClip[0].x = Math.random()*400+50;
var y0 = myClip[0].y = Math.random()*50+50;
var x1 = myClip[1].x = Math.random()*400+50;
var y1 = myClip[1].y = Math.random()*50+50;
var x2 = myClip[2].x = Math.random()*400+50;
var y2 = myClip[2].y = Math.random()*50+50;
var x3 = myClip[3].x = Math.random()*400+50;
var y3 = myClip[3].y = Math.random()*50+50;
var x4 = myClip[4].x = Math.random()*400+50;
var y4 = myClip[4].y = Math.random()*50+50;
var x5 = myClip[5].x = Math.random()*400+50;
var y5 = myClip[5].y = Math.random()*50+50;
var x6 = myClip[6].x = Math.random()*400+50;
var y6 = myClip[6].y = Math.random()*50+50;
/*var x7 = myClip[7].x = Math.random()*400+50;
var y7 = myClip[7].y = Math.random()*50+50;
var x8 = myClip[8].x = Math.random()*400+50;
var y8 = myClip[8].y = Math.random()*50+50;
var x9 = myClip[9].x = Math.random()*400+50;
var y9 = myClip[9].y = Math.random()*50+50;*/
var j:Number;
for (var k:Number = 0; k < numClips; k++) {
myClip[k].addEventListener("mouseDown", pieceMove);
myClip[k].addEventListener("mouseUp", pieceMove);
}
function pieceMove(evt:Event):void {
if (evt.type == "mouseDown") {
//mySound.play();
evt.target.startDrag();
}
else if (evt.type == "mouseUp") {
//mySound.play();
evt.target.stopDrag();
for (j = 0; j < numClips; j++) {
if (evt.target.name == "piece" + j &&
evt.target.hitTestObject(nph[j]) == true) {
removeChild(myClip[j]);
nph[j].alpha = 0;
tpg[j].alpha = 100;
score++;
}
else if (evt.target.name == "piece" + j) {
evt.target.x = Math.random()*400+50;
evt.target.y = Math.random()*50+50;
}
}
scor.text = score.toString();
if (score == 10) {
msgbox.text = "Congratulations !";
}
}
}
I'm using Flash CS3 because it's required by my course I'm taking so a suggestion to use a different version of flash is not helpful. Thanks.
答案 0 :(得分:0)
所以我所做的不是使用嵌入式影片剪辑,而是在主时间轴内重新制作它并且工作正常。它因此而变得更加混乱,但它没有问题。不知道为什么它没有以第一种方式工作。