How to Make Currency in ActionScript Games

In an ActionScript game, as in many other games, currency is the central focus, with the player who has the most money at the end of the game winding up the winner. ActionScript developers often have to adapt games to different foreign markets, and making a game compatible for a different foreign market often requires that the game code include a currency converter. In ActionScript investor games, in which different currencies are traded to make a profit, a currency converter is also required.

Instructions

    • 1

      Start the Flash program. Click "Flash File(ActionScript 3.0)" from the splash window to create a new file for the AS3 Flash.

    • 2

      Select "Actions" from the "Window" menu on the main Flash menu bar to open the ActionScript 3 editor. Position your mouse cursor on the first line of the ActionScript 3 editor. Click your mouse button, and type in the code below to declare the variables that will store the currency conversion factors.

      var United_States_to_Canadian: number = 0.66;

    • 3

      Type, starting at the next line of the ActionScript 3 editor, the code to create two TextFields: one text field that will be used to enter in the United States dollar amount and the other text field to display the equivalent amount in Canadian dollars.

      var UnitedStates_Currency:TextField = new TextField();

      var Canadian_Currency:TextField = new TextField();

    • 4

      Type, starting at the next line of the ActionScript 3 editor, the code that will convert the number entered into the United States text field to a number from text. (All text entered in a text field is text. Text from text fields needs to operated on as a number must be converted to a number with the number method.)

      var A: number

      A = number(UnitedStates_Currency);

    • 5

      Type, starting at the next line of the ActionScript 3 editor, the code that will create the function that will perform the conversion of United States currency to Canadian currency.

      function convert_fn(event:KeyboardEvent);number

      {

      if (event.keyCode == Keyboard.ENTER)

      {

      var result:number = United_States_to_Canadian*A

      return result;

      }

    • 6

      Type, starting at the next line of the ActionScript 3 editor, the code that will call the "convert_fn" function when the "Enter" key is depressed when the mouse cursor is in the "UnitedStates_Currency" text field.

      UnitedStates_Currency.addEventListener(KeyboardEvent.KEY_DOWN, convert_fn)

Learnify Hub © www.0685.com All Rights Reserved