【问题标题】:Flash CS3 startDrag on object in movieclip inside main flaFlash CS3 startDrag 在主 fla 内的movieclip 中的对象上
【发布时间】:2015-01-21 13:06:12
【问题描述】:

我到处寻找有此问题的其他人,但似乎找不到解决方案,所以在这里。

我在我的教科书中找到了一个关于 Flash CS3 的关于益智游戏的教程。这很简单,如果你抓住一块它会调用 startDrag 和 stopDrag。

所以我开始制作自己的游戏,并在其中创建了一个名为puzzleGame 的movieClip。我已经将原始教程中的代码复制到了我的puzzleGame movieClip 中,但是当我测试它时,我总是收到一个错误消息,提示startDrag 和stopDrag 不是一个函数。这与我的主舞台中的这个电影剪辑有关。

如果我将代码更改为 this.startDrag 那么它实际上会拖动整个框架。我认为无论出于何种原因,它都没有深入到我拖动的实际对象,而只是看到我触摸了影片剪辑本身。

这有意义吗?

这是我的 frame2 代码。

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.                                                                         

【问题讨论】:

    标签: flash event-handling mouseevent flash-cs3 adobe-flash-cs3


    【解决方案1】:

    所以我所做的不是使用嵌入的影片剪辑,而是在我的主时间轴内重新制作它,它工作正常。因此它更混乱,但它可以毫无问题地工作。不知道为什么第一种方式不起作用。

    【讨论】:

      猜你喜欢
      • 2011-08-29
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 2017-10-17
      • 2011-04-05
      相关资源
      最近更新 更多