Saturday, October 19, 2013

Simple HTML Page Creator in AS3

I wrote this simple HTML page generation tool for the small flash game portal site: http://play.flaswf.tk. Just fill in some embedding parameters for the swf, such as the url, width and height, then it can produce the simple page for the game.

Nothing complicated here. UI is using MinimalComps and the AS3 code only does some string replacing for an HTML template.
Two things to note:
First, for multi line string in AS3 (e.g., the string variable in my code for holding the HTML template), we can use the "CDATA" tag:

//http://dougmccune.com/blog/2007/05/15/multi-line-strings-in-actionscript-3/
private var myString:String = ( <![CDATA[
    Here is my string 
    that spans multiple 
    lines.
    ]]> ).toString();

Second, the build-in AS3 string replace function can only replace the first match in the string. A custom replace function is needed for replacing all the occurrences:
//http://actionscriptsnips.blogspot.com/2009/07/search-and-replace.html
  private function strReplace(str:String, search:String, replace:String):String
  {
   return str.split(search).join(replace);
  }
 
Finally, you can try the tool here:
http://play.flaswf.tk/SubmitYourGame.html

And the source code:
http://flaswf.googlecode.com/svn/trunk/HTMLWebCreator/

No comments:

Post a Comment

Sponsors