How to Make a Flash AS3 RPG

Role playing games, games where players assume the role of a fictional character, such as an employee, can be used for training employees and for career counseling. With the Flash ActionScript 3 (AS3) programming language, RPG games can be custom-made for your specific needs. With AS3 programming commands and Flash's graphic design-based interface, you have all the tools needed to make your virtual RPG characater walk, talk, work, sing, and more. Although it doesn't take much code to make a simple RPG game, creating highly animated role playing games requires the creation of many illustrations, sound, and video tracks.

Things You'll Need

  • Adobe Flash Professional CS3, CS4 or CS5 Versions
Show More

Instructions

    • 1

      Import the graphics for the waitress RPG.. These include a waitress and one customer. Use the "Import" option from the "File" menu to import the graphic files to the Flash stage.

    • 2

      Use the "Convert to Symbol" option from the Modify menu to convert the waitress and the customer graphic to movie clips. Assign the waitress symbol a class name of "waitress" and the customer a class name of "customer." Enter the class name in the "Class" text box in the "Convert to Symbol" dialog box that appears after you select the "Convert to Symbol" option.

    • 3

      Open the ActionScript 3 editor and type in the code to place a text box that will be used to display the waitress messages to the customers and the waitress manager's messages.

      var waitressMessage: TextField = new TextField();

      waitressMessage.x = 100;

      waitressMessage.y = 100;

      waitressMessage.width = 200;

      waitressMessage.text = "Waiting for a customer"

      waitressMessage.multiline = true;

      waitressMessage.wordWrap = true;

      addChild(waitressMessage);

      The code positions a text field with a width of 200 pixels that will display multiline messages in the text field that is placed on the stage at location (100, 200). The addChild method is used to place the text field on the Flash stage.

    • 4

      Type on the next line of the ActionScript 3 editor the code to place an instance of the customer graphic and the waitress graphic on the stage.

      var customer1:customer = new customer();

      customer1.x = 0;

      customer1.y = 300;

      addChild(customer1);

      var waitress1:waitress = new waitress();

      waitress1.x = 400;

      waitress1.y = 400;

      addChild(waitress);

    • 5

      Type, starting on the next line of the ActionScript 3 editor the code that will move the customer across the Flash stage every time Flash displays a new animation frame and display a message in the text field if the waitress fails to catch the customer's attention.

      customer1.addEventListener(Event.ENTER_FRAME, move_fn);

      function move_fn(moveevent:Event): void

      {customer1.x = customer1.x +1;

      if (customer1.x > 400) {waitressMessage.text = "The customer just walked out the door"}

      };

      The addEventListener method executes the code in the function named "move_fn" every time Flash displays a new frame. The customer is moved one pixel to the right every time a new frame is displayed. If the customer has moved to the right more than 400 pixels the message "The customer just walked out the door" is displayed.

    • 6

      Type in the code to control the movements of the waitress such that when the left, right, down, or up arrow keys is pressed, the waitress moves in the corresponding direction.

      stage.addEventListener(KeyboardEvent.KEY_DOWN, whichKey)

      function whichKey(event:KeyboardEvent):

      void

      {

      if (event.keyCode == Keyboard.LEFT){waitress.x = waitress.x - 5};

      if (event.keyCode == Keyboard.RIGHT){waitress.x = waitress.x + 5};

      if (event.keyCode == Keyboard.UP){waitress.y = waitress.y - 5};

      if (event.keyCode == Keyboard.DOWN){waitress.y = waitress.y + 5};

      if (waitress1.x > customer1.x + 10 && waitress.y < customer1.y) {customer1.removeEventListener

      (Event.ENTER_FRAME, move_fn); waitressMessage.text = "Would you like to be seated?";}

      };

      The AS3 conditional (if then) statement

      if (waitress1.x > customer1.x + 10 && waitress.y < customer1.y) {customer1.removeEventListener

      (Event.ENTER_FRAME, move_fn); waitressMessage.text = "Would you like to be seated?";}

      will detect when the waitress is more that 10 pixels to the right of the customer (customer1.x) and is positioned above the customer (customer1.y) When the waitress is within that range, the customer1 event listener will be removed which will prevent the customer from moving when Flash displays a new animation frame.

    • 7

      Click "Test Movie" from the "Control" menu. Use the up, down, right, and left arrows to reposition the waitress. Note that when the waitress is to the right and above the customer, the message "Would you like to be seated?" is displayed. If the customer moves off the stage, the message "You missed a customer, the manager would like to speak with you" is displayed.

Learnify Hub © www.0685.com All Rights Reserved