代码之家  ›  专栏  ›  技术社区  ›  Daniel

在movieclip中切换Flash场景

  •  1
  • Daniel  · 技术社区  · 15 年前

    如何使用flash cs5和actionscript 3切换flash movieclip对象中的场景?

    1 回复  |  直到 11 年前
        1
  •  1
  •   AdamScott    15 年前

    嗨,Dani,

    首先,不建议在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.

    希望能帮上忙。如果您有任何问题,请评论此答案!