The web site for Flash ActionScript 3.0 game developers

 
         
   

Flash Game University Blog

FlashGameU.com Video Tutorial: Creating a Snake Game, Part 1

In this mini-chapter two-part episode, Gary Rosenzweig starts building a snake game in ActionScript 3.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

Ask Gary: Variable Names

Hi Gary,
I teach AS and have for some time been telling my students to append
suffixes such as _mc to movieClips, _btn to buttons, etc. This seems to
really make life easier when troubleshooting. I have to wonder if I'm
really out of the loop on this one because I don't see anyone else doing
that.

In AS3 if you type your variables well, then you really don't need to use suffixes to help identify variables when troubleshooting. Furthermore, if you use descriptive names, then the problem goes away. For instance, if I was putting playing cards on the stage, I would place them all in a sprite and call the sprite "cardSprite".
While I'm not a huge fan of using fixed suffixes like "_mc" in variable names, I'm not against it either. Whatever makes it easier for you or your programming team to get the job done.

FlashGameU.com Video Tutorial: Playing Multiple Flash Movies Inside a Single Flash Application

Gary Rosenzweig takes a look at how to put two Flash games together, inside of a single Flash movie. The trick is to use the Loader object.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Playing a Song With a Toggle Button

Steve wrote in about the Toggle Button episode.

Hi Gary,

I'd followed your AS3 toggle button tutorial to Play/Pause a song.
1. What can I do to allow the song to be played again by clicking the toggle button?
2. What is needed to make the toggle button to take on the "play" state when the song has finished on its own?

Expanding on the earlier tutorial about creating a Toggle Button, here's how to link the toggle button to a piece of music in the library and to have the toggle button react properly when the song is done.

View video in your browser.

Download QuickTime Movie.

Download the source file.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Shuffling Arrays

This tutorial shows you how to create an array with a random arrangement of items, like a shuffled deck of cards, or a list of sounds to be played in a random order.

View video in your browser.

Download QuickTime Movie.

Subscribe via iTunes.

Ask Gary: AS3 Capitalization

Gary,

Is there a rule for knowing when a built in function, property, etc
will start with a capital, be all caps, or start lower case? For example,
addEventListener starts lower case, MouseEvent start upper case, and
ROLL_OVER is all caps. I am coming out of ASP programming and just
keeping my variables the right case and remembering all the new commands
is hard enough - but having to remember which commands are which case is a
bit much. Let me know if there is a good rule to remember these by.

Thanks.
Brandon

Good question. This is especially important when you consider that AS3 is case sensitive. So addEventListener is a function, but AddEventListener is nothing.
It seems the convention is that functions start with lowercase, then capitalize each word after that. Like gotoAndStop. Classes start with capital letters, like the Math in Math.random(). Constants use all caps and underlines between words, like ENTER_FRAME.
But I wouldn't take that for granted. And it doesn't really matter too much because the auto-completion in the AS3 programming windows will list the command for you as you type.
What I would avoid though is using capitalization to differentiate between functions or functions and variables. For instance, I wouldn't use moveObject as a function and then moveobject as a variable. It works, but I wouldn't do it.
I do kinda break that rule sometimes when I have a movie clip that by its nature will only be on the stage once. For instance, the space ship in an asteroids game. I might call that SpaceShip in the library and as a class, and then spaceShip will be the instance name. It makes it easier for me to find the movie clip in the Library based on the instance name I'm using in the code.

FlashGameU.com Video Tutorial: Matching Game with Card Pairs

This tutorial shows you how to alter the matching game in the book ActionScript 3.0 Game Programming University to use pairs of cards instead of identical cards.

View video in your browser.

Download QuickTime Movie.

Download the source files.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Dynamic Buttons

How to create simple dynamic buttons that allow you to create identical buttons with different labels. The buttons also behave like buttons, with rollover and down states.

View video in your browser.

Download QuickTime Movie.

Download the source files.

Subscribe via iTunes.

FlashGameU.com Video Tutorial: Saving Local Data

How to use the SharedObject to save bits of data to the local hard drive for use at another time.

View video in your browser.

Download QuickTime Movie.

Subscribe via iTunes.

Ask Gary: Repositioning Word Search

hi Gary,

enjoying the book, and probably ahead of myself BUT, how can I change
where the wordsearch grid and wordlist appear on the stage if I change the
size of the stage?

I've made the stage larger, and I would like to put the grid and wordlist
in the center - how do I change the X/Y?

thanks...
skillspider

There are many ways to do this. One would be to change some constants in the code. If you look at the start of the script, you will see an offset for the letter grid.

static const offset:Point = new Point(15,15);

You can simply change this to 115,115 to move the grid to the right 100 pixels and down 100 pixels.
Similarly, you can move the word list over by changing this line:

newWord.x = 400;

What I would do first, is to make it dependent on the same offset constant. So change it to this:

newWord.x = offset.x + 385;

Now it will always be to the right of the letter grid. All you need to do is change the offset constant to move both elements.
Another way to do this would be to simply move the gameDprite. Every game element is in the gameSprite, which is at position 0,0 by default. So moving it to 100,100 will have the same effect as the other changes. Here is that code inserted into the startWordSearch function.

// set up the sprites
gameSprite = new Sprite();
gameSprite.x = 100;
gameSprite.y = 100;
addChild(gameSprite);
Syndicate content

Copyright Gary Rosenzweig