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
}
}
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:
Gameand have theGameclass load inIntrobefore it starts the main code.Introand load in theGameclass after the intro has finished.IntroandGameindividually.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
Gameclass. Make a similar MovieClip for theIntroclass. Use your new class to create new instances of each at appropriate times programmatically.