![](/img/trans.png)
[英]Is there a way to create a class inside the main .fla file of a Flash CS3 app?
[英]Flash CS3 startDrag on object in movieclip inside main fla
我到處都在搜索其他有此問題的人,但似乎找不到解決方案。
我在教科書中找到了有關益智游戲的Flash CS3教程。 非常簡單,如果您抓取一塊,則將其稱為startDrag和stopDrag。
因此,我開始制作自己的游戲,並在其中創建了一個名為PuzzleGame的movieClip。 我已經將代碼從原始教程復制到了我的PuzzleGame movieClip內部,但是當我對其進行測試時,總是會收到一條錯誤消息,說startDrag和stopDrag不是函數。 這與我主舞台內的動畫片段有關。
如果我將代碼更改為this.startDrag,那么它實際上將拖動整個框架。 我認為無論出於何種原因,它都不會深入到Im拖動的實際對象上,而只是讓我觸摸到動畫片段本身。
這有意義嗎?
這是我的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.
因此,我要做的不是使用嵌入式影片剪輯,而是在主時間軸內對其進行了重新制作,並且效果很好。 因此,它比較雜亂,但沒有問題。 不知道為什么它不能一開始就起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.