I often answer questions on the forums over at Actionscript.org and I noticed that people are always asking about communicating between classes. In particular, people ask how you can change a variable in the document class (main class) from another class. So instead of repeating myself, I'll post it here.
Short answer: MovieClip.(this.parent).variable=xxx;
Long Answer:
You have to be careful when you access variables in one class from another class. Things can get confusing pretty quickly. But a good example of when it is kosher is when you have an enemy in a game; when it is hit by a bullet, it tells the document class to increase the score. It's simple and foolproof enough.
Okay, I set up a flash document with Main.as as the document class. I declare an object obj which is an instance of the class Obj. I declare a variable pvar, which we will set to 1 and then set to 2 by running a function in Obj.as:
package {
import flash.display.MovieClip;
public class Main extends MovieClip {
public var obj:Obj;
public var pvar:int;
public function Main() {
pvar=1;
obj = new Obj;addChild(obj);
obj.ResetVar();
trace(pvar);
}//game
}
}
Can you see that? It's easy to run a function on a separate class... we just say obj.ResetVar();
Of course, we haven't created Obj.as yet, so let's do that now:
package {
import flash.display.MovieClip;
public class Obj extends MovieClip {
public function Obj() {}//Obj
public function ResetVar(){
MovieClip(this.parent).pvar=2;
}//rv
}
}
Now you can see how we use the line MovieClip(this.parent).pvar=2; to refer to the parent of this movie clip and set pvar to 2.
Try it and you should get the trace '2'.
Got it? Good.
If you have any questions or the explanation isn't clear, please feel free to leave a comment. If you're looking for some more Flash tutorials or projects, try here: flashbynight.com/tutes
Monday, September 5, 2011
Sunday, September 4, 2011
Things Fall Down
Time for a new Flash game and I hope you like it.
In Things Fall Down, the sky is falling and everything else along with it. Keep jumping up and keep yourself above ground.
There are fifteen short levels that would probably take around one hour to finish.
The game is at: http://www.flashbynight.com/thingsfalldown
Have a look at some screenshots here:
If you've played some of my games before, you'll recognise the graphical style. Enjoy!
In Things Fall Down, the sky is falling and everything else along with it. Keep jumping up and keep yourself above ground.
There are fifteen short levels that would probably take around one hour to finish.
The game is at: http://www.flashbynight.com/thingsfalldown
Have a look at some screenshots here:
If you've played some of my games before, you'll recognise the graphical style. Enjoy!
Labels:
AAA games,
casual games,
falling games,
flash,
platformers
Friday, June 10, 2011
New Tute! Guide to coding a hangman game.
Here is a step-by-step guide to creating a hangman game in Flash CS5 with AS3. Feel free to play around with the code:
http://flashbynight.com/tutes/hangman
Here is a downloadable pdf version:
http://www.scribd.com/doc/57512256/Create-a-HangMan-Game-in-Flash-AS3-Tutorial
Enjoy!
http://flashbynight.com/tutes/hangman
Here is a downloadable pdf version:
http://www.scribd.com/doc/57512256/Create-a-HangMan-Game-in-Flash-AS3-Tutorial
Enjoy!
Monday, May 23, 2011
Saturday, April 16, 2011
What Makes Final Fantasy XIII a Great Game?
I've just finished Final Fantasy 13 - the first FF I've played - and I want to share some thoughts on the game.
What makes Final Fantasy a great game?
1 Lightning
I just love Lightning's character. She's tough and she's cool, like a female Clint Eastwood. Sometimes morally ambiguous ("a target's a target"), she does soften somewhat throughout the game. A soldier by profession, a loner by nature, Lightning turns her back on the army to go on a one-woman suicide mission to save her sister. Somewhat reluctantly, she picks up an entourage along the way.
Game designers, please give us more characters like Lightning.
2 Anarchistic Themes
Like many Japanese games, the storyline is hard to follow at times and too confusing to summarize here. The underlying theme, though, is clear: The Government lies to the people and abuses them; most people swallow the lies, but a few enlightened anti-authority types refuse to toe the line. Another theme is the Government's use of an invented 'enemy' to control the masses through fear, as espoused by Neo-con favorite Leo Strauss (http://en.wikipedia.org/wiki/Leo_Strauss).
Just take a look at our fine anarchist heroes:
3 Value
I put 70 hours in to beat the game. While many Western games are this long, it is unusual to find a Western game with this quality graphics and artwork of that length (the game takes 3 discs on the 360). Western-made games with the best quality graphics are often less than 10 hours to play through. How the Japanese manage it, I don't know.
Have a look at this eye-candy:
That's a wrap, folks, and that's why Final Fantasy 13 is a great game. Buy it!
What makes Final Fantasy a great game?
1 Lightning
I just love Lightning's character. She's tough and she's cool, like a female Clint Eastwood. Sometimes morally ambiguous ("a target's a target"), she does soften somewhat throughout the game. A soldier by profession, a loner by nature, Lightning turns her back on the army to go on a one-woman suicide mission to save her sister. Somewhat reluctantly, she picks up an entourage along the way.
Game designers, please give us more characters like Lightning.
![]() |
| Lightning |
Like many Japanese games, the storyline is hard to follow at times and too confusing to summarize here. The underlying theme, though, is clear: The Government lies to the people and abuses them; most people swallow the lies, but a few enlightened anti-authority types refuse to toe the line. Another theme is the Government's use of an invented 'enemy' to control the masses through fear, as espoused by Neo-con favorite Leo Strauss (http://en.wikipedia.org/wiki/Leo_Strauss).
Just take a look at our fine anarchist heroes:
![]() |
| "No rules, authority or obligations" |
3 Value
I put 70 hours in to beat the game. While many Western games are this long, it is unusual to find a Western game with this quality graphics and artwork of that length (the game takes 3 discs on the 360). Western-made games with the best quality graphics are often less than 10 hours to play through. How the Japanese manage it, I don't know.
Have a look at this eye-candy:
![]() |
| "I made a promise and I'll see it through" |
That's a wrap, folks, and that's why Final Fantasy 13 is a great game. Buy it!
Friday, April 1, 2011
Chobo: Trapped in a Tetris Game
So I had this premise for a game where the character is trapped inside a round of Tetris, and I made this into a Flash game.
Okay, well the game is similar to Tetris. I had to play around with the mechanics to get it to work nicely and I threw in a few enemies and power-ups.
I invite you to play the result:
Click here to play Chobo
Okay, well the game is similar to Tetris. I had to play around with the mechanics to get it to work nicely and I threw in a few enemies and power-ups.
I invite you to play the result:
Click here to play Chobo
Saturday, March 26, 2011
Mamas, let your babies grow up to be gamers
A lot of my friends have kids now and I've been trying to explain to them that gaming is a healthy and beneficial activity, a comment which is often met with some skepticism.
People seem to have three main objections to allowing their kids to game:
1 "There's too much violence in games"
Sure. The same way there's too much violence in movies. Games have an extensive ratings system that has probably been prone to less controversy over the years than the movie ratings system. As a parent, when you buy a game, if it's not clear from the packaging whether the game is suitable for kids, the store clerk should be able to help you. Or simply do some research online. Isn't it worth ten minutes of research for a game that will keep your kids happy and engaged for dozens of hours (compared to a DVD which is over in one and a half hours)? On top of all that, gaming consoles come with family settings.
2 "Isn't gaming an antisocial activity?"
Sure. The same way that reading a book is antisocial. Except that books don't have multiplayer. Many games have a co-op mode where a player plays alongside a friend, or multiplayer, where a player plays with a whole group of friends. Besides that, being a gamer means, like with any hobby, your child will be able to connect and make friends with fellow gamers at school and other places.
Always remember that video games are an evolution of sports and board games. Early video games were less social due to the constraints of technology that we have now overcome.
3 "Isn't gaming unhealthy?"
No way. Console games are extremely sophisticated and it takes time to learn how to play them well. This means that your brain is in learning mode for a lot of the gameplay. For children, this enhances the fact that learning is a pleasurable experience. (Something schools try to make them 'unlearn'.) Games teach perseverance, strategic thinking and many other positive skills.
So Mamas, please let your babies grow up to be gamers - it's good for them.
Subscribe to:
Posts (Atom)







