Game Development Reference
In-Depth Information
function onTextLoad(e:Event) {
trace( " Text: " + e.target.data);
}
All this code does is load a text file and trace what is in it. In and of
itself, this is not especially useful until you consider what you could
put inside the file. Maybe your game has a lot of text dialogue and
you don
'
t want it mixed with your code, or a bunch of legal copy you
don
twanttomesswithpastinginsideatextfieldinFlash.Word-
based, trivia, and many other puzzle games are also good candidates
for loading in external content, allowing you to add new content with-
out having to republish the game file. We
'
ll look at an example of this
type of game shortly, in the form of a crossword puzzle.
'
XML
By default, a URLLoader simply loads in plain text, which is fine for
most applications involving local files. By itself, however, text does
not lend a great deal of flexibility. It needs to be organized into a
format that has a structure. This is where XML comes in. If you
re
not already familiar with it, XML is, in brief, a markup language (in
format similar to HTML) for organizing data into a structured for-
mat. Here is an example of some simple XML defining a quiz:
'
< quiz >
< problem >
< question > What does this topic cover? < /question >
< answer > Flash Game Development < /answer >
< answer > Java Game Development < /answer >
< answer > C++ Game Development < /answer >
< /problem >
< problem > etc. < /problem >
< /quiz >
As you can see, XML is incredibly flexible, allowing you to
define exactly how you want your data structured. XML structures
can become extremely complex, particularly for large-scale applica-
tions, but this example also shows how simple it can be. In this
case, we
ve defined that a quiz contains problems. Each problem
has a question and three answers, the first of which is correct. By
setting up your data with a logical hierarchy, we can access it easily
from inside Flash.
'
E4X
IfyouhadworkedwithXMLinActionScript1or2,youwould
know how unwieldy it was to handle. Unless you used a very
robust parser, most changes to the structure of the XML would
Search Nedrilad ::




Custom Search