无法获得KidByName starling阶段

时间:2013-04-18 13:03:33

标签: actionscript-3 object stage

我正在尝试从一个外部类“子弹”中获取一个名为“_shooterHero”的starling阶段上的对象的引用。

我尝试过将getChildByName用于:

starling.core.stagestarling.current.nativeStage,但没有运气

现在的代码:

var hero= Starling.current.stage.getChildByName("_shooterHero");
trace (hero.name)

1 个答案:

答案 0 :(得分:0)

有几种方法可以解决您的问题:

  1. 让英雄公开访问。当您创建新的英雄(无论在哪里)时,您还可以添加公共getter / setter方法以允许外部类访问它。

  2. 创建一个可由singleton getInstance()模式引用的“模型”类。然后按(1)进行。

  3. 你确定精灵已被添加到舞台上吗?你可以通过Starling.current.stage.getChildByName(hero)来检查这个;虽然为此需要访问英雄变量。

相关问题