加载场景1后,所有影片剪辑都为空!为什么?
OK
在Scene
1中,按下按钮后,用户转到Scene
2。从那里返回到Scene
1后,其他中的所有影片剪辑图层为空。
这是我的代码,转到场景
1:
MovieClip(this.root).gotoAndStop(1, "Scene 1");
为什么???
OK
In Scene
1, after pressing a button user goes to Scene
2. After coming back from that to Scene
1, All movie clips in other layers are null.
This is my code that goes to Scene
1:
MovieClip(this.root).gotoAndStop(1, "Scene 1");
WHY???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在代码中引用了时间轴实例并更改了场景,它们将丢失引用。当您离开场景时,场景的实例也会被删除,并在您再次进入时重新创建。
我建议您根本不要使用场景,并考虑为您的 Flash 文件使用文档类。也许你已经拥有了。
如果您仍然想使用场景,请将 init 函数放在每个场景的第一帧中。这将使您可以轻松设置场景参考。
If you have references to a timeline instance in your code and change scene they will lose the references. The instances of the scene will also be removed when you leave the scene, and recreated when you enter again.
I recommend you to not use scenes at all and look into using a document class for your flash file. Maybe you already have that.
If you still want to use scenes, put a init function in the first frame of each scene. That will make it easy for you to setup the scene references.
您可以同时拥有场景和文档类——不幸的是,它只是没有很好地说明如何做到这一点。以下是有关发生的情况以及如何解决该问题的一些信息 http://www.developria.com/2010/04/combining-the-timeline-with-oo.html。
请注意,您不应该从子影片剪辑中引用父影片剪辑,并且即使在 AS2 时代,使用 _root 也被认为是不好的做法(例如,一旦您将影片加载到另一部电影中,它就会中断)。
相反,从子类分派事件并在主文档中捕获它们,并让主文档移动播放头。
You can have both scenes and a document Class--it's just not well documented on how to do it, unfortunately. Here is some information on what is going on and how to resolve it http://www.developria.com/2010/04/combining-the-timeline-with-oo.html .
Note that you should not be referencing the parent from child movie clips, and using _root was considered bad practice even in the AS2 days (it breaks as soon as you load your movie inside another movie, for instance).
Instead, dispatch events from the child Classes and catch them in the main document and have the main document move the playhead.