Step 4. Making The First Room
Create a new keyframe inside the game MovieClip, in the same MovieClip where the cutscene takes place, if you did one. This should be the 2nd frame or 3rd if you did a cutscene.
Create the background for it and convert it into a Symbol, calling it whatever with a suffix of bg or background.
Exit the symbol and convert it into another symbol, simply call it whatever the room is called.
This is the current setup
Hopefully that wasn’t too confusing.
We are now ready to add whatever we want inside the room symbol. If you want the object to be interacted with or have animation, make it a MovieClip and place it inside of the room symbol and not the background symbol.
Inside the Game Movieclip, make a new layer and place it at the top. Make a bunch of empty frames. Select a frame, then in the properties, give each frame a name, like calling the main menu “menu” and the intro “intro”. These are called labels and are an easier way to be able to go to these rooms than using frame numbers.
Now that we've sorted that out, we can go back to the menu and make the start button work. First, we need to give the Game MovieClip an instance name. Now we can do this
this.startbtn.addEventListener(MouseEvent.CLICK, startgame); function startgame(event:MouseEvent):void { Object(root).game.gotoAndStop(“eduardos”); }
(Pro Tip: Press Ctrl+Shift+F to auto format, which makes it look nicer)
Make sure to put inside of the gotoAndStop the label of the frame you want it to go next, which may be an intro or the first room, and put it in quotes. Oh, and that root thing? Well..
In AS3, there are 2 ways to call an object: Relative and absolute.
Relative is with where you are currently at, so if I wanted to call an object inside of another object, you can do
this.headmc.eyesmc.gotoAndPlay(1);
You can also go backwards and refer to a parent of an object, although it's a little clunky. Using Object(this.parent.parent)
Absolute is starting from the root and going down the branches, using the Object(root) prefix.
Object(root).guymc.headmc.eyes.mc.gotoAndPlay(1);
Flash has a menu in the Actions panel (looks like a crosshair) to be able to call movieclips, buttons, and texts quickly, with the option to choose to call the object relatively or absolutely. My rule of thumb is, if you are referring to parent objects, use absolute, else use relative.
We can test the game by pressing Ctrl+Enter and….. Oh wait, we forgot the most important keyword in the entirety of Flash (according to my brother) stop(); which does exactly that. This needs to be added inside the Game MovieClip, with all the labels on their own layer that simply has stop();
(Pro Tip #2: Name your layers so you know where everything is)
Oh, and one last thing before we continue, add semicolons to the end of a line (as long as there aren’t any brackets). This is used to indicate to Flash that it’s the end of the line and to move on to the next one. Luckily, Flash isn’t strict on it (unlike other languages) and will let you get away with not putting any. But, you know, it’s common practice to do it, and I’ve had cases (okay, one) where a semicolon made it work.
Okay, so now that root is explained, we can now test the game by pressing Ctrl+Enter and click! Anytime the compiler (the magic thing that turns it into a swf file) throws an error, the final result will just play as if it were an animation. Getting a warning won’t do this, although it should probably be fixed either way.