0
我試圖訪問存儲在文檔類中的變量healthState
和healthInt
。我已經試過MovieClip(parent).healthState++;
,正如你所看到的,但是我得到了未定義屬性健康狀態的錯誤1120訪問。該變量是公共的。聲明變量時還有什麼我應該做的嗎?如何在as3中訪問其父子項中的變量
private function collisionDetection() {
for (var i = 0; i < enemies.length; i++) {
var type = getQualifiedClassName(enemies[i]);
var hype = myMath.distanceBetween(enemies[i],player);
if (hype < 10 && enemies[i] is Swirl && enemies[i].parent != null) {
MovieClip(this).removeChild(enemies[i]);
MovieClip(parent).healthState++;
if (healthState <= 8) {
MovieClip(parent).healthInt--;
trace(healthInt);
hearts.gotoAndStop(healthState);
}
if (MovieClip(parent).healthInt <= 0) {
MovieClip(parent).desiredLabel = 'GameOver';
MovieClip(parent).tweenOut();
gameOver = true;
removeChild(enemies);
squares.splice(0);
enemies.splice(0);
parent.removeChild(this);
}
}
}
}