The Click Me Challenge – Haxe Edition

Welcome to The Click Me Challenge – Haxe Edition.

If you are unfamiliar with this challenge, I point you to:

http://andrewwooldridge.com/blog/2009/11/12/the-click-me-challenge/

http://davidbarneswork.posterous.com/click-me-challenge-should-replace-hello-world

This is the Haxe/Flash edition of the Click Me Challenge, where I will take us step by step through the process from absolutely nothing to a version on par with the reference implementation.

Part one of the challenge: Create a Haxe Development environment.

  1. Download the Haxe manual install zip file from http://haxe.org/download.
  2. Unzip the contents into a clever location like C:\swfdev or something.
  3. Add C:\swfdev\haxe-2.05-win (or whatever file you wind up unzipping into) to your path.
  4. Download SwfMill from http://swfmill.org/
  5. Unzip the swfmill zip into the C:\swfdev folder
  6. Add C:\swfdev\swfmill to your path

Part two of the challenge: Test the build environment.

  1. Create a subfolder of c:\swfdev called clickme001
  2. Create a number of text files:
    1. build.bat
    2. compile.hxml
    3. ClickMe001.hx
    4. ClickMe001.html
  3. Enter the text following this list into the respective files.
  4. Execute build.bat.
  5. Open ClickMe001.html.
  6. Behold a white rectangle on a light gray background.

ClickMe001.hx:

class ClickMe001 {
 static function main() {
 }
}

compile.hxml:

-swf ClickMe001.swf
-main ClickMe001
-swf-header 200:100:40:FF0000
-swf-version 8

build.bat:

haxe compile.hxml
pause

ClickMe001.html:

<html>
<head><title>ClickMe001</title></head>
<body bgcolor="#dddddd">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
 width="200"
 height="100"
 id="haxe"
 align="middle">
<param name="movie" value="ClickMe001.swf"/>
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="salign" value="lt" />
<param name="bgcolor" value="#ffffff"/>
<embed src="ClickMe001.swf"
 bgcolor="#ffffff"
 width="200"
 height="100"
 name="haxe"
 quality="high"
 align="middle"
 allowScriptAccess="always"
 type="application/x-shockwave-flash"
 pluginspage="http://www.macromedia.com/go/getflashplayer"
/>
</object>
</body>
</html>

Part three of the challenge is achieving parity with the reference implementation.

  1. Modify ClickMe001.hx
  2. Modify compile.hxml
  3. Create buildresources.bat
  4. Create resources.xml
  5. Execute buildresources.bat
  6. Execute build.bat
  7. Open ClickMe001.html
  8. Behold the contents of the Click Me Challenge

ClickMe001.hx:

class ClickMe001 {
 static var button:flash.MovieClip;
 static var points:flash.TextField;
 static var score:Int = 0;
 static var pressed:Bool = false;
 static function main() {
 button = flash.Lib.current.attachMovie("button","",flash.Lib.current.getNextHighestDepth());
 button._x = 5;
 button._y =5;
 button._width = 190;
 button._height = 20;
 button.onPress = onButtonPress;
 button.onRelease = onButtonRelease;
 button.onReleaseOutside = onButtonReleaseOutside;
 points = flash.Lib.current.createTextField("points",flash.Lib.current.getNextHighestDepth(),5,30,90,20);
 points.text = "0";
 points.selectable = false;
 }
 static function onButtonPress() {
 pressed = true;
 }
 static function onButtonRelease() {
 if(pressed){
 score++;
 points.text = Std.string(score);
 }
 pressed = false;
 }
 static function onButtonReleaseOutside() {
 pressed = false;
 }
}

compile.hxml:

-swf ClickMe001.swf
-main ClickMe001
-swf-header 200:100:40:FF0000
-swf-lib resources.swf
-swf-version 8

buildresources.bat:

swfmill simple resources.xml resources.swf

resources.xml:

<?xml version="1.0" encoding="iso-8859-1" ?>
<movie>
 <frame>
 <library>
 <clip id="button" import="button.png"/>
 </library>
 </frame>
</movie>

And there you have it.  The Click Me challenge in haXe for Flash.

Result: http://playdeez.com/blogdownloads/clickme001.html

Source: http://playdeez.com/blogdownloads/clickme001.zip

Advertisements

Tags: , ,

One Response to “The Click Me Challenge – Haxe Edition”

  1. John Hattan Says:

    Oh, and speaking of “occasional” games and Haxe, tell me you’ve been playing mybrute.com. It’s a perfect example of an occasional game, as you can only play it for about five minutes a day. And it’s done in Haxe. And it’s quite good.

    http://shmookybooky.mybrute.com/

    (That’s my unstoppable wall of death of a brute)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: