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: 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:

private var myString:String = ( <![CDATA[
    Here is my string 
    that spans multiple 
    ]]> ).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:
  private function strReplace(str:String, search:String, replace:String):String
   return str.split(search).join(replace);
Finally, you can try the tool here:

And the source code:

No comments:

Post a Comment