Game Development Reference
In-Depth Information
_content.clues.appendChild(down);
}
var file:FileReference = new FileReference();
file.save(_content, " crosssword.xml " );
}
When creating an XML within ActionScript, you don
'
thaveto
enclose it in
or convert it from a string. You simply start typing it,
hencetheonelinetocreatethe _content container for the XML. To
insert ActionScript values in the midst of raw XML, simply use braces
({}) around the expression that needs to be evaluated. In this case, the
first line creates the main nodes with the puzzle width and height
attributes and two child nodes: puzzle and clues. It then runs through
the tile list and builds all the rows for the puzzle. The appendChild
method is called, which adds each row to the bottom of the puzzle
XMLList, like a push to an array. Then, the across and down clues are
iterated and appended as well. Finally, the FileReference save method
is called. It brings up a system file dialog window and saves the XML
as text data to the file selected. The second parameter is only a
suggestion
“”
the end user can select whatever file name they want.
Sending Data Back Out
While the local file saving abilities in the FileReference class are great,
the real power comes from saving data to a remote destination, such
as a database. Data such as high-score leaderboards, user profiles,
and more are all great candidates for XML formatting. To get the
information to the database, it must get through some data processing
(or middleware ) layer, such as WebServices, AMF (Remoting), or stan-
dard form posts. Here is a quick example of what the latter might look
like, simply posting the raw XML to a receiving PHP page.
var myXML:XML = < crossword width= " 10 " height= " 10 ">< puzzle/ >
< clues/ >< /crossword > ;
var request:URLRequest = new URLRequest( " myservice.php " );
request.contentType = " text/xml " ;
request.data = myXML.toXMLString();
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader(request);
Just as the URLLoader is the core class for loading remote data into
Flash, it is also the sending mechanism when combined with a data-
laden URLRequest. In this example, we simply format the request to
notify the receiving page that it contains incoming XML content. Of
course, sending the XML in its raw form like this is not particularly
secure
most any savvy hacker will be able to use any number of
HTTP monitoring tools to see the XML being sent (or any being
received for that matter). For some data, such as public high-score
Search Nedrilad ::




Custom Search