Stefan4024
Stefan4024

Reputation: 694

How to apply class to timeline in AS3?

I'm working on a little project right now in ActionScript 3. The project is almost finished, but i want to add an intro frame. And then i get a problem.

I have 2 .as file with code. One is called Game, and the another is called intro. Game is the document class.

I have 2 frames and when i start the game, Game class is applied to both of them. So how can i apply Game class to 2nd frame and Intro class to the 1st.

The code is a little bit too long, so wouldn't upload it. Here is some part of it. Also code works perfectly so ai don't have problem with it.

Game.as

package  {
      public class Game extends MovieClip {
             public function Game () {
                      //constructor
             }
             // some other functions
       }
 }

Intro.as

 package  {
      public class Introextends MovieClip {
             public function Intro() {
                      //constructor
             }
             // some other functions
       }
 }

Upvotes: 0

Views: 326

Answers (1)

Alexis King
Alexis King

Reputation: 43842

You cannot dynamically change the Document Class in AS3, nor would it make any sense from an OOP perspective to be able to. You have three options:

  1. Keep the document class as Game and have the Game class load in Intro before it starts the main code.
  2. Change the document class to Intro and load in the Game class after the intro has finished.
  3. Create a new class to be a "holder" class, and use that as the document class instead. Then load in Intro and Game individually.

I would go with Option 3, since it's probably the easiest to implement and it makes the most sense. You can move all the frames from your old main timeline into a new MovieClip, then link that MovieClip to the Game class. Make a similar MovieClip for the Intro class. Use your new class to create new instances of each at appropriate times programmatically.

Upvotes: 3

Related Questions