我在下面有这个类结构
public class Main extends Sprite
{
private var myObject:MyObject;
private var mySecondObject:MySecondObject;
private var myThirdObject:MyThirdObject;
public function Main()
{
myObject = new MyObject();// also extends sprite
addChild(myObject );
mySecondsObject = new MySecondObject(this);
addChild(mySecondsObject);
myThirdObject = new MyThirdObject(this);
addChild(myThirdObject);
}
public function getMyObject():MyObject
{
return myObject;
}
}
public class MySecondObject extends Sprite
{
private var _main:Main;
private var _myObject:MyObject;
public function MySecondObject(main:Main)
{
_main = main;
_myObject = _main.getMyObject();
// do some stuff with _myObject, add on enter frame listener etc...
}
public function start(): { /* do some stuff */}
public function stop(): { /* do some stuff */}
}
public class MyThirdObject extends Sprite
{
private var _main:Main;
private var _myObject:MyObject;
public function MyThirdObject(main:Main)
{
_main = main;
_myObject = _main.getMyObject();
// do some stuff with _myObject, add on enter frame listener etc...
}
public function start(): { /* do some stuff */}
public function stop(): { /* do some stuff */}
}
当我使用MySecondObject和MyThirdObject
执行此操作时出现的问题是MyObject的sprite消失了 MySecondObject.stop();
MyThirdObject.start();
MyObject仍然存在于内存中,但我无法在舞台上看到它。 WTF ??? :)
为了说清楚我不会使用removeChild()从舞台上删除任何内容。
我试图解决的问题是我想拥有从MySecondObject和MyThirdObject更新MyObject状态的访问器
答案 0 :(得分:0)
问题解决了。我改为在舞台上添加所有的孩子,比如this.stage.addChild(child)而不是this.addChild(child),所以现在它可以正常工作并在开始/停止后显示舞台上的所有对象