Archive for the ‘Future Professionals’ category

Creating a quiz game using ActionScript

May 1st, 2009
    Setting up the Project

  1. Open a new Flash document.
  2. Click on Layer 1, Frame 1. Add a stop(); action to stop the playhead.
  3. On a new line in the code, establish a variable to hold the score.
    The code so far:
    stop();
    score=0;

    We set up the score variable here so we can change it as the user gets questions right.
  4. Create a new layer in frame 1.
  5. Create text as a title for your game (so the user isn’t staring at a white screen).
  6. Making a Button

  7. That’s great, but we need a way to get past this screen. We’ll need a button. Click on Insert->New Symbol and choose ‘Button’.
  8. Buttons have an Up, Over, Down, and Hit. Up is its natural state. Over is if some hovers a mouse over the button. Down is what it looks like when it gets clicked. Hit is the Hit Zone – if you want a bigger area to register if it’s been clicked on or not. Normally Hit is the size of a box around the button.
  9. Make a keyframe in each area to change the states of the buttons (what they look like). Notice that you can insert multiple layers.
  10. Drag that button onto the stage.
  11. The button is clickable, but it doesn’t know what else to do. With the button selected (blue highlight around it), open up the ActionScript for that button.
  12. Telling the Program to go to the Next Part

  13. Type on( . Remember from previous lessons that when we see the parentheses, it means the function is calling/looking for a variable. Most modern versions of Flash will try and guess which one you want. Select press. (When someone clicks the button, it goes. You could choose release and the user could click and hold and then go when the user releases the mouseclick.)
  14. Add a funky bracket ( { is called a brace, to be technical) to start your list of commands.
    The code should now be:
    on(press) {
  15. Start a new line to maintain style.
  16. Type in gotoAndPlay(2); Notice that the ‘A’ and the ‘P’ are capitalized. Also look at how the function calls a variable – the number ‘2’ – to tell the game to go to frame 2.
    The code now is:
    on(press) {
    gotoAndPlay(2);
    }
  17. If you run the program right now, when you click, it will go to frame 2 (or even just consider frame 1 the end of the movie if you haven’t added anything yet to frame 2) but then loop back to frame 1. We need to put a stop(); code in frame 2 just like we did for frame 1. You’ll need to insert a blank keyframe and then click on the ActionScript arrow.
  18. Once you’ve added the stop();, on a different layer create text with your question.
  19. Use the Same Button Multiple Times to Make Your Life Easier

  20. We need buttons for our answers. If we create one button in the Flash library, we can then drag it in multiple times and not have to re-do animations. Create that button.
  21. Drag the button from the library onto the stage. Create a text box next to the button that has an answer.
  22. Drag the button from the library again onto the stage for the second answer. Put a text box next to the button with an answer.
  23. Checking for the Wrong Answer

  24. Click on the button next to the wrong answer to select it (blue outline).
  25. Let’s add some code for the wrong answer. Let’s add a gotoAndPlay(3); to the button (with the on(press) and all that) to take the user to frame 3, which is where we’ll mock them for getting the wrong answer. (Mock them nicely and politely.)
  26. Make sure to add a stop(); code in frame 3 to avoid the jumping loop. You’ll need to insert a blank keyframe.
  27. Create your end of game screen. Be nice and include a button to take us back to frame 1.
  28. Checking for the Right Answer

  29. Let’s say the user got the question right. Go back to frame 2 and edit the ActionScript for the correct answer button.
  30. Send the user to the next question – frame 4 – with a gotoAndPlay(4); What’s different this time, though, is that we need to add to the score. On a new line in the ActionScript type in score = score + 10; We just took the score and added 10 points to it. (It will still complete the rest of your list of commands – but to keep it straight in the minds of the humans who may be reading over your code later, add to the score first and then put in the goto.
    The code should look like:
    on(press){
    gotoAndPlay(4);
    score = score + 10;
    }
  31. Displaying a Score

  32. On frame 2, create a new layer. Let’s label what the user is looking at. Create a text box somewhere on the screen that says ‘Score’. If it’s on it’s own layer and it’s own keyframe, it will constantly say ‘Score’ throughout the whole program.
  33. Now let’s show the actual score. Click on the tool to make a text box, but instead of creating a text box, just click where you want to show the score.
  34. In the Properties at the bottom of the work area, change it from Static to Dynamic text. Dynamic and Static are just like with characters in a story – dynamic changes, static stays the same.
  35. In that text’s Properties, there’s a place called ‘Var: ‘ with an input box next to it. Type in score. It will now show the value for score. Make sure that you don’t put this in frame 1, because frame 1 is where we initialize/set up the variable.
  36. Thoughts to Enhance the Game

  37. You can add to score whenever the user clicks on the right answer button. You can subtract from score when a user gets the wrong answer.
  38. You can add as many buttons as you like – you don’t just have to have two questions.
  39. Not all buttons need to be easily seen. You could say “Click on the duck” but have the Up be blank and have the Over show a duck. The user would have to roll around the screen to try and find the right button.
  40. You can create a variable called whichframe to control which frame a gotoAndPlay goes to. Instead of gotoAndPlay(4); it could be gotoAndPlay(whichframe);

Re-Posting: Flash Game Sample

April 8th, 2009

Here’s a re-posting of a sample from last year. Use this to add some code to your circleman movies.

Today at Future Professionals I could see that some were almost ready to start programming in Flash, but were intimidated by the time that it takes to get used to ActionScript.

It, literally, is another language. Just like Spanish or French, it takes some getting used to. One of the ways that I became familiar with programming was by taking apart other people’s programs.

So I give to you a game that I made for my friend Brian. (In my high school group of friends was Tommy, Tommy, Brian, Brian, and Mike.)

Click on the .fla file to download the source. (Depending on where you are, you may need to right click/control click.)

Brianland Source File

Test the movie in Flash to see what it does (spacebar fires and arrows move) and then experiment.

As you experiment, try to:

  1. Increase the amount of money the character gets
  2. Increase the number of hook gnomes
  3. Change the amazing artwork

Once you are comfortable with editing the parts of the program, try editing other people’s files and finding tutorials.

Re-posting of ActionScript Tutorial

March 27th, 2009

Once you’ve mastered this, try out the Pong tutorial by the Flash Ninja Clan here.

(and for Future Professionals, but we’ve been working on this)

The first type of code that I like to introduce is “stop();”. Put this in the ActionScript for the first frame. Test the movie. Instead of moving on through the frames, it stops in frame 1. How exciting.

Let’s animate a figure.
circleman
This is circleman. He is a very complex character with artwork that took me hours to draw.

To be able to easily reuse circleman, instead of drawing him on the stage, I made him a separate movie clip in the Flash file’s library. That way I don’t have to spend hours re-drawing him.

Right now he’s kindof boring in his new layer on frame 1, especially since the “stop();” command doesn’t move the animation anywhere. But for this movie, all of the fun will happen in one frame.

Make sure that circleman is selected, click on his ActionScript button, and type in the code that you see in the picture:
Move Left code

The onClipEvent(load) is a one time thing when that movie clip shows up in the frame the first time around. You’re setting up the initial values of the speed.

The onClipEvent(enterFrame) is every time the frame loops. With the LEFT function, it’s making your xspeed value a negative one. Outside of the Key.isDown(Key.LEFT) function the _x and _y is being added to whatever your xspeed and yspeed values are. It will do this each time the frame loops (many times per second). This creates the constant motion. If you don’t like the constant motion, you could put the _x += xspeed; part inside the Key.isDown function to add the xspeed only when the key is down.

Remember: Brackets start and stop a function. Every time there’s an open bracket it has to close the function somewhere with a close bracket.

Back to the Key.isDown, the way we’ve got it set up, circleman moves left until he is stuck in the netherworld called “Offscreen” with no hope of return. Add some UP, DOWN, and RIGHT Key.isDown functions.

Boundaries
Here’s where stuff gets crazy.

Create a movie called “bounds”.
bounds
This will be your environment/world/level.
Put the movie bounds on the stage. Name its instance “wall”.
wall

In circleman’s ActionScript, add a hitTest after your Key.isDown code but before your _y+=yspeed; stuff.
hitTest
If the character hits the bounds, it stops and then moves to new x,y coordinates.

This ActionScript dictionary is officially your best friend.

Photoshop Contest #3: Anime Character

March 25th, 2009

The Results:
picture-11

And the winner of the best iPhone app is…

March 4th, 2009

iMario! Nicely done.

Tie-breaker: Best iPhone App

March 4th, 2009

Make your choice and click on “Submit” to break the tie. The last PhotoShop contest? Turn yourself into an anime character. Remember: lots of extreme colors and exaggerated features.

Voting is closed.

iPhone Voting

February 25th, 2009

Click here to submit your picture of the perfect iPhone application.

Voting is closed.

Files for the iPhone Contest

February 11th, 2009

iphone-menu1
sms
iphone_phone-1

We’ll put them up and vote on the best next Wednesday.

Future Professionals Contest #2

February 4th, 2009

The perfect iPhone application can be found by clicking here.

Future Professionals Contest #1 Voting has Begun

January 27th, 2009

The photos look great. Remember that you’re picking the one that looks the most realistic, whether it looks like a screenshot from a game or a photo from a celebrity magazine.

Click here to vote. You’ll log in just like you log in at school.

We won’t be meeting on Wednesday since it’s a half day, but if you like PhotoShop, check out the web app Pixlr.

And yes, it’s free. Woohoo and all that.