如何使用 Flash CS5 和 ActionScript 3 在 Flash MovieClip 对象中切换场景?
问问题
6726 次
1 回答
1
嗨,丹妮,
首先,不推荐在 AS3 中的 MovieClip 对象中编码,也不推荐使用场景。
为什么?
- 如果您是初学者,在 MovieClip 对象中编码可能很诱人,这没关系。
但是,如果您对资产和代码的可重用性很认真,您可能希望将视觉与逻辑分离。
我建议你写下你的逻辑- 从主要时间线
- 来自外部类(并使用 OOP)这太棒了!
- 由于时间线和代码问题,场景很糟糕。
如果您的某些代码在一个场景中,则其他场景可能无法访问它。
说够了,这是您需要的帮助。
如何在 Flash MovieClip 对象中切换场景
此代码旨在位于 MovieClip 帧中
// === Let's put the stage in a variable (cleaner) ===
var main:MovieClip = this.parent as MovieClip;
// this.parent will return the DisplayObject of parent the current clip.
// You need to cast [... as MovieClip] to not cause errors because Flash
// thinks it is only a DisplayObject
// === Here's the interresting part ===
main.gotoAndPlay(0, "Scene 2");
// We tell the main timeline to go to frame 0 in the "Scene 2"
// Be cautious, it must be spelled exactly as displayed in Flash (IDE)
不要忘记:您的剪辑更深(在剪辑中多次嵌入),您需要更多的“父级”。
var main:MovieClip = this.parent.parent as MovieClip;
// If your object is inside a MovieClip who is itself in a MovieClip
// Tip: How much time you need to push the Back button to go to the timeline
// is the number of parents you need to write.
希望这有帮助。如果您有任何问题,请评论此答案!
于 2010-08-21T12:35:35.380 回答