Thursday, July 23, 2009
Reclaiming my zeal!
I've found an awesome AS3 tutorial! It's on Michael James William's blog and it's all about creating your own 'Avoider' game using Action Script 3... speaking of AS3 - holy cow it's different from AS2, this isn't some minor revision! It's like learning a whole new language. Kinda reminds me of when I was learning C++ because it's more OOP.
Anyways, Mike's (can I call you Mike?) tutorial - which is using FrozenHaddock's Avoider Game tutorial and upgrading it to AS3 - is a great resource for learning AS3, and if you're just starting to play with Flash that's where you want to begin. So go there, check it out! Participate in the comments if you have a problem... I know I will be :)
Included with the later 'chapters' of his tutorial are some 'challenges' - I love this part! The purpose of his tutorial isn't just to walk you through doing everything. Like a good teacher, he sets out some goals for you to try to accomplish on your own, and then provides support if (WHEN) you need it by means of the comments section.
If you haven't gone through the tutorial yet, go do it! I'm going to post what I did on some of the challenges here.
Chapter 7 Challenges
One of the challenges is creating a second button on the menu screen, so that one would start the game with mouse control and the other with keyboard control. I mulled over this for three days!
My first step was to duplicate the startButton in AvoiderGame.fla, I named the instance of the copy - kbStartButton. I also edited the button so that when I hovered my mouse over it it said "Keyboard" and the original startButton says "Mouse"
My next steps were in creating an event listener for my 'keyboard control' button (I named the instance kbStartButton (Line 4 in the code below)
You notice, I also changed onClickStart to onClickMouse.
And also in the function...
Plus a new function that we referenced in the event listener (onClickKeyboard)
We referenced a .MOUSE and a .KEYBOARD navigation event, so go to our NavigationEvent.as file and add:
Now, going back to the DocumentClass.as file, change your constructor to:
Go down to the onRequestStart function, and add this to the top:
Now, go to AvoiderGame.as - don't worry, we'll be back here in a minute!
Create a variable for choosing the mouse, I called it iChooseMouse
and change the constructor for AvoiderGame to accept this new variable. While you're at it, add a line that makes useMouseControl equal to iChooseMouse.
Now, stroll back to DocumentClass.as and change every instance of
Save all your .AS files and give it a test run. Should work!