【发布时间】:2014-06-19 01:23:31
【问题描述】:
所以我有 2 个类 Main 和 Enemy。在 Enemy 类中,我需要使用在 Main 类中声明的变量。
这是我的 Main 类:
public class Script extends MovieClip {
var hero:MovieClip;
var enemy:MovieClip; //These variables are only for example
public function Game() {
hero.x = 100;
enemy.x = 200; // that's only example
}
function collisionDetected() {
enemy.hitBack(); // this is how I call hitBack function from Enemy class
}
}
这是我的Enemy类:
public class Enemy extends MovieClip {
private var count = 0;
public function hitBack() {
count = 0;
this.addEventListener(Event.ENTER_FRAME, myEnterFrame);
}
private function myEnterFrame(e:Script)
{
if (count == 20) this.removeEventListener(Event.ENTER_FRAME, myEnterFrame);
else
{
count++;
if (hero.x < enemy.x) { //here I need to use variables from Main class
this.x -= 4;
}
else {
this.x += 4;
}
}
}
我收到以下错误:
1120: Access of undefined property hero.
1120: Access of undefined property enemy.
【问题讨论】:
标签: actionscript-3 flash class actionscript movieclip