ARTDM 170, Week9: Encapsulation + Paper Prototypes


Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

ARTDM 170, Week9: Encapsulation + Paper Prototypes

  1. 1. ARTDM 170, Week 9: Encapsulation and Paper Prototypes Gilbert Guerrero
  2. 2. Homework • Please put your files in a folder with your last name and first initial • Put the folder in my dropbox • Example: smith-h MyAnimation.swf MyProjectDescription.pdf
  3. 3. Open Flash • Create a new ActionScript 3.0 document: MyEncap.fla • Create a new ActionScript file:
  4. 4. Encapsulation
  5. 5. Intro and Ending Screens • To encapsulate a movie, use 3 frames ‣ 1st frame holds the intro screen and a button ‣ 2nd frame holds the game or movie ‣ 3rd frame holds a game over screen and a restart button
  6. 6. Flash Buttons To create a button: • Create a new symbol in the Library • Symbol type: Button • In a button, each frame is a button state: ‣ Up - no user interaction ‣ Over - user mouse hovers over ‣ Down - user clicks the button ‣ Hit - invisible shape defines whatʼs clickable
  7. 7. Encapsulation: Frame 1 In the first frame: • Add a button to the stage • Name the instance of the button “play_btn” • Select the first frame and add this script: play_btn.addEventListener(MouseEvent.CLICK,startGame); function startGame(event:MouseEvent) { gotoAndStop("playgame"); } stop();
  8. 8. Encapsulation: Frame 2 • Create a second frame • In the Properties panel, label the frame “playgame” • Create a MovieClip symbol in the Library • Right click on the symbol to open Properties... ‣ Click Export for Animation ‣ Enter your movieʼs class name in the class field, e.g. MyAnimation • Drop an instance of the symbol onto the stage and place it at (0,0) in the upper left corner of the stage
  9. 9. Encapsulation: Frame 3 In the third frame: • Add a button to the stage • Name the instance of the button “replay_btn” • Select the first frame and add this script: replay_btn.addEventListener(MouseEvent.CLICK,playAgain); function playAgain(event:MouseEvent) { gotoAndStop("playgame"); } In a game, the final frame of the encapsulation would be your Game Over screen.
  10. 10. Getting to the third frame Your encapsulated movie needs to provide a way to load the third frame. • Create a variable in your ActionScript class public var bounceCount:Number = 0; • Add 1 to the variable each time an event occurs bounceCount++; • When the variable reaches its limit, send the movie to the “gameover” frame (you must refer to the root movie) if (bounceCount >= 10000) { MovieClip(root).gotoAndStop("gameover"); }
  11. 11. Paper Prototypes
  12. 12. Building Paper Prototypes • Cheap, easy, and effective • Paper Prototyping on A List Apart
  13. 13. Arrays
  14. 14. Storing and Retrieving • Arrays can be used to store data fruits = {“apples”,“oranges”,“bananas”} • Data can be retrieved from arrays using the index numbers trace(fruits[0]); //apples trace(fruits[1]); //oranges trace(fruits[2]); //bananas // I like to eat apples and oranges. trace("I like to eat "+fruits[0]+" and "+fruits[1]+"."); • More about Arrays next week...
  15. 15. Randomization • Generate a random number between 0 and .999999 Math.random() • Round down using Math.floor and to multiply Math.random by a number get a random integer between zero and your number //generates integers from 0 to 29 Math.floor(Math.random()*30)
  16. 16. Homework, due Oct 21 • Read Chapter 5: Arrays in the ActionScript 3.0 Cookbook, p103-136.  • Be sure you learn about these functions: ‣ array.push() ‣ array.splice() ‣ array.concat() ‣ and Looping through an Array (see section 5.2)