Editing XML text in Scuba Diver

Author: Matt Slaybaugh
Date: October 25, 2006
Level: Beginner

Summary

Scuba Diver is a game in which the player uses the arrow keys to move the swimmer to the goal, off the right side of the screen, before running out of air. Avoid colliding with the fish, which makes you lose air faster!

In this tutorial, you will change the values of some of the variables in an external XML file used in the game.

Experience Needed
  • Using a text editor
Software
  • Any text editor, such as Notepad
Files — Scuba_XML_tutorial.zip (224 KB)
  • labels.xml
  • myglife_scuba.swf
License — "Scuba Diver" (c) 2007, World Wide Workshop Foundation

This software is licensed to the public under the CC-GNU GPL.


The Scuba Diver game uses text gathered from an external XML file
for the labels above, rather than hard-coding them in the application.
Description
Change the text used in the game.

The Scuba Diver game uses an XML file, named labels.xml to store the text used in the game. This way, the language of the game can be changed without having to reprogram the Flash application

XML stands for Extensible Markup Language and is very similar to HTML. You can edit XML files as you would HTML files, with any text editor.

Below is the full contents of the file labels.xml.

<?xml version="1.0"?>
<labels>
      <startButton name="START"/>
      <playAgainButton name="PLAY AGAIN"/>
      <tryAgainButton name="TRY AGAIN"/>
      <congratulationsText name="CONGRATULATIONS YOU WIN!"/>
      <sorryText name="SORRY YOU DIDN'T MAKE IT THIS TIME."/>
</labels>

There are five places in the Scuba Diver game where text appears on the screen:

  • The 'Start' button at the very beginning
  • The 'Play again' button when the game is over
  • The 'Try again' button when the game is lost
  • 'Congratulations' text that appears when the game is won
  • 'Sorry' text that appears when the game is lost

In the XML code above, the five labels are defined and given unique, descriptive names (eg. startButton). These names are what the Flash application will be looking for, so if we change them the game won't work properly.

Each label definition includes an attribute (eg. name) that has a value (eg. "START"). These values are the strings of text that will appear in the game.


The 'Start' button with updated, translated text
  1. Open labels.xml in your text editor.
  2. Change the text of the last label ('sorryText') to "You ran out of air!"
  3. If we wanted to have this game appear on a French-language site we would need to translate all the labels. Change the value of the first label ('startButton') to Commencez (French for "Start").
  4. Open myglife_scuba.swf in a browser. You should see that the Start button now reads "Commencez". If you play the game and lose, you will see the change to 'sorryText'.
  5. Change the rest of the labels to whatever you like.