我是AS3的新手,我正在尝试在我的代码中添加动态运行状况。 这是我基于动态健康的代码。
var currentHealth:int = 5000;
var totalHealth:int = 10000;
//Dynamic health
var healthPack:medipack = new medipack();
healthPack.width = 30;
healthPack.height = 30;
healthPack.x = Math.random() * stage.stageWidth;
healthPack.y = Math.random() * stage.stageHeight;
stage.addChild(healthPack);
和
//Display current health
health.bar.width = 300 * (currentHealth / totalHealth);
currentHealth -= 1;
//detecting collision with health
if (stage.contains(healthPack))
{
if (player_mc.hitTestObject(healthPack))
{
currentHealth += 5000;
healthPack.parent.removeChild(healthPack);
}
}
我目前在我的图书馆中与健康相关的符号是:
HealthBarBg(实例名称为bar),是healthBar的一个实例 healthBar 和medipack
每当我运行此代码时,我都会收到以下错误:
Scene 1, Layer 'Actions', Frame 2, Line 91, Column 2 1120: Access of undefined property healthBar.
我不确定我做错了什么,任何帮助都是适当的,谢谢。