    /* Sample Animation one can use to create dynamic buttons -- written by Alexis Wilke for Made to Order Software Corp. (c) 2002-2007 */
    /* This button animation shows how external parameters can be used within a Flash movie */

    /*

    Copyright (c) 2002-2007 Made to Order Software Corp.

    Permission is hereby granted, free of charge, to any
    person obtaining a copy of this software and
    associated documentation files (the "Software"), to
    deal in the Software without restriction, including
    without limitation the rights to use, copy, modify,
    merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom
    the Software is furnished to do so, subject to the
    following conditions:

    The above copyright notice and this permission notice
    shall be included in all copies or substantial
    portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
    ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
    LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
    EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.

    */

    // Some parameters can be defined on the command line at
    // generation time:
    //
    // MUST HAVE:
    //	... -Dscreen_width=<value> -Dscreen_height=<value> ...
    //					the size of the final movie in
    //					pixels
    //
    // OPTIONAL:
    //	... -Dborder_width=<value> ...
    //					with of the 3D effect border
    //
    //	... -Dfont_height=<value> -Dfont_name=<string> ...
    //					the name and height of the font;
    //					font infos are hard coded and
    //					can't be any more dynamic than
    //					this.
    //
    // The following are parameters you can define in your HTML
    // page so as to be able to re-use this button multiple times.
    // Note that they all are optional.
    //
    //	... label=<string> ...		the button label (the text
    //					written in the button); spaces
    //					must be noted as %20
    //
    //	... url=<string> ...		the destination URL; don't forget
    //					that any & character must be noted
    //					as %27; also spaces as %20
    //
    //	... bgcolor=#<RRGGBB> ...	defines the background color of the
    //					button; each of the R, G and B letters
    //					must be an hexadecimal digit; note
    //					that the highlighting is done by adding
    //					0x11 to each color component; thus a
    //					maximum color of 0xEE should be used
    //					so as not to lose that feature
    //
    // The following is an example of a URL used to display the button in the
    // SSWF web page. Note that I wrote it on multiple line for the sake of
    // clarity, but in the real page it has to be on a single line:
    //
    //	SRC="button.swf?
    //		bgcolor=#6688CC
    //		&label=Download%20%3Cb%3ESSWF%3C/b%3E%3Cbr%3E%3Ci%3ENow!
    //		&url=http://sourceforge.net/project/showfiles.php?group_id=63702%26release_id=120796"

    border_size = defined("border_width") ? border_width : 5;
    font_size = defined("font_height") ? font_height : 22;
    font_set = defined("font_name") ? font_name : "Arial";

    rectangle "screen" { 0, 0, screen_width, screen_height };

    edges "corner" {
    	0, -screen_height;
    	screen_width, 0;
    	-border_size, border_size;
    	border_size * 2 - screen_width, 0;
    	0, screen_height - border_size * 2;
    	-border_size, border_size;
    };
    edges "inside" {
    	0, border_size * 2 - screen_height;
    	screen_width - border_size * 2, 0;
    	0, screen_height - border_size * 2;
    	border_size * 2 - screen_width, 0;
    };

    fill style "fill_dark_grey" { sswf.col.grey5; };
    fill style "fill_grey" { sswf.col.grey10; };
    fill style "fill_white" { sswf.col.grey13; };

    shape "top_left" {
    	rect { -1, -1, screen_width + 1, screen_height + 1 };
    	fill_white; move: 0, screen_height; corner;
    };
    shape "bottom_right" {
    	rect { -1, -1, screen_width + 1, screen_height + 1 };
    	//show_bounds: true;
    	//show_origin: true;
    	fill_dark_grey; move: 0, screen_height; corner;
    };
    shape "active_area" {
    	rect {
    		border_size - 1, border_size - 1,
    		screen_width - border_size + 1, screen_height - border_size + 1
    	};
    	//show_bounds: true;
    	fill_grey; move: border_size, screen_height - border_size; inside;
    };

    ////////////////////////////////////////////////////
    // The N, e and w letters
    // We create seperate sprites so we can animate them
    // separatly (see the swap/swap_letter functions below)
    ////////////////////////////////////////////////////
    sprite "tl" {
    	place object {
    		id: top_left;
    		depth: 1;
    	};
    	show frame;
    };
    sprite "br" {
    	place object {
    		id: bottom_right;
    		depth: 1;
    		matrix { translate: screen_width, screen_height; scale: -1 };
    	};
    	show frame;
    };
    sprite "area" {
    	place object {
    		id: active_area;
    		depth: 1;
    	};
    	show frame;
    };
    sprite "aa1" {
    	replace object {
    		"area";
    		id: area;
    		depth: 1;
    	};
    	do action {
    		// function to transform one character to a value from 0 to 15
    		// the expression goes like this:
    		//	v = (ord(bgcolor[index++]) - 0x30) & 0x1F;
    		//	if(v >= 16) v += 10 - 17;
    		//	return v;
    		// note: the index register is incremented automatically
    		//	 the '#' character(s) are silently skipped
    		// register 1 holds bgcolor
    		// register 2 holds index (starts at 0)
    		function "hex" {
    			action  "push data" {
    				register: 1;
    				integer: 1;
    				register: 2;
    			};
    			action "increment";
    			action "store register" { 2 };
    			action "swap";
    			action "substring";
    			action "duplicate";
    			action "push data" {
    				string: "#";
    			};
    			action "equal";
    			action "if true" { "zero" };
    			action "ord";
    			action "push data" { integer: -0x30; };
    			action "add";
    			action "push data" { integer: 0x1F; };
    			action "and";		// convert a-f to A-F!
    			action "duplicate";
    			action "push data" {
    				integer: 16;
    			};
    			action "less than";
    			action "if true" { "done" };
    			action "push data" {
    				integer: 0x0A - 0x11;
    			};
    			action "add";
    			action "branch" { "done" };
    			label { "zero" };
    			action "pop";
    			action "push data" {
    				integer: 0;
    			};
    			label { "done" };
    			action "return";
    		};

    		action "push data" {
    			null: 0;
    			string: "/:bgcolor";
    		};
    		action "get variable";
    		action "store register" { 1 };	// r1 = $(/:bgcolor);
    		action "equal";			// if bgcolor is null -> keep default color
    		action "if true" { "done" };

    		action "push data" {
    			string: "hex";
    			integer: 0;
    			register: 1;
    		};

    		action "string length";
    		action "store register" { 3 };	// r3 = strlen($/:bgcolor);
    		action "pop";
    		action "store register" { 2 };	// r2 = 0
    		action "swap";
    		action "call function";		// . = hex();

    		// the following transform the bgcolor=#RRGGBB in an integer
    		label { "next_char" };
    		action "push data" {
    			integer: 4;
    		};
    		action "shl";			// . <<= 4
    		action "push data" {
    			integer: 0;
    			string: "hex";
    		};
    		action "call function";
    		action "or";			// . |= hex()

    		action "push data" {
    			register: 2;
    			register: 3;
    		};
    		action "less than";		// if r2 < r3 -> next char
    		action "if true" { "next_char" };

    		// put that color in the result now
    		action "push data" {
    			integer: 1;
    			string: "setRGB";
    			string: "area";
    			integer: 1;
    			string: "Color";
    		};
    		action "new";
    		action "swap";
    		action "call method";		// (new Color("area"))->setRGB(...)
    						// where the ... is the integer generated
    						// from the /:bgcolor string

    		label { "done" };
    		action "stop";
    	};
    	show frame;
    };
    sprite "aa2" {
    	place object {
    		id: aa1;
    		depth: 1;
    		color transform { add: 0x11 / 255.0, 0x11 / 255.0, 0x11 / 255.0; };
    	};
    	show frame;
    };

    font "font_selection" {
    	font_set;
    	type: "unicode";
    };

    edit text "button_text" {
    	rectangle { border_size * 5, border_size * 4,
    			screen_width - border_size * 5, screen_height - border_size * 4 };
    	word_wrap: true;
    	multiline: true;
    	password: false;
    	readonly: true;
    	no_select: true;
    	border: false;
    	outline: false;
    	max_length: 100;
    	variable: "button_label";
    	init: "<p align=\"center\">Please,<br>Click Here</p>";
    	html: true;
    	align: "center";
    	text setup {
    		sswf.col.black;
    		id: font_selection, font_size;
    	};
    };

    button "my_button" {
    	state {
    		flags: 0x08;
    		depth: 1;
    		id: active_area;
    	};
    	state {
    		flags: 0x01;
    		depth: 11;
    		id: aa1;
    	};
    	state {
    		flags: 0x03;
    		depth: 12;
    		id: tl;
    	};
    	state {
    		flags: 0x03;
    		depth: 13;
    		id: br;
    	};
    	state {
    		flags: 0x06;
    		depth: 21;
    		id: aa2;
    	};
    	state {
    		flags: 0x04;
    		depth: 32;
    		id: tl;
    		matrix { translate: screen_width, screen_height; scale: -1 };
    	};
    	state {
    		flags: 0x04;
    		depth: 33;
    		id: br;
    		matrix { translate: screen_width, screen_height; scale: -1 };
    	};
    	state {
    		flags: 0x03;
    		depth: 34;
    		id: button_text;
    	};
    	state {
    		flags: 0x04;
    		depth: 35;
    		id: button_text;
    		matrix { translate: 5, 5; };
    	};
    	action "push data" {
    		string: "/:url";
    	};
    	action "get variable";
    	action "push data" {
    		string: "_top";
    	};
    	action "url";

    	/* the following action script is shorter but requires V5.x
    	action "push data" {
    		string: "_top";
    		string: "/:url";
    	};
    	action "get variable";
    	action "swap";
    	action "url";
    	*/
    };

    /* I started by writing the following script when I found
     * out that we couldn't include a \n dynamically!!!
     * Instead I use the HTML flag now
     * I left the script here, in case you wanted to use it.
     * Note that the last caracter in the string isn't checked.
     */
    list "unused" {
    	action "push data" {
    		string: "button_label";
    		integer: 1;
    		string: "label";
    	};
    	action "store register" { 1 };
    	action "string length";
    	action "store register" { 3 };
    	action "pop";
    	action "store register" { 2 };
    	action "pop";

    	label { "repeat" };
    	action "push data" {
    		register: 2;

    		string: "\\";
    		register: 1;
    		register: 2;
    		integer: 1;
    	};
    	action "substring";		// read next character
    	action "equal";
    	action "logical not";		// if label[idx] != '\\' -> no_backslash
    	action "if true" { "no_backslash" };
    	action "push data" {
    		register: 3;

    		string: "n";

    		register: 1;		// the label
    		integer: 1;
    		register: 2;
    	};
    	action "decrement";
    	action "substring";		// label = label[1..idx - 1] + label[idx + 1..max - 1]
    	action "push data" {
    		register: 1;
    		register: 2;
    	};
    	action "increment";
    	action "duplicate";
    	action "push data" {
    		register: 3;
    	};
    	action "substract";
    	action "substring";
    	action "concatenate string";
    	action "store register" { 1 };

    	action "push data" {
    		register: 2;
    		integer: 1;
    	};

    	action "substring";
    	//action "store register" { x }; -- would be useful if more than just \n supported
    	action "equal";
    	action "logical not";		// if label[idx] != 'n' -> backslash_removed
    	action "if true" { "backslash_removed" };

    	action "push data" {
    		string: "\n";		// <-- this doesn't work 8-{
    		register: 1;
    		integer: 1;
    		register: 2;
    	};
    	action "decrement";
    	action "substring";		// we had a \n, so add it
    	action "swap";
    	action "concatenate string";	// label = label[0..idx - 1] + '\n' + label[idx + 2..max - 1]
    	action "push data" {
    		register: 1;
    		register: 2;
    	};
    	action "increment";
    	action "duplicate";
    	action "push data" {
    		register: 3;
    	};
    	action "substract";
    	action "substring";
    	action "concatenate string";
    	action "store register" { 1 };
    	action "pop";

    	label { "backslash_removed" };
    	action "decrement";		// string_length--;
    	action "store register" { 3 };
    	action "pop";

    	label { "no_backslash" };
    	action "increment";		// idx++;
    	action "store register" { 2 };

    	action "push data" {
    		register: 3;
    	};
    	action "less than";		// if idx < string_length -> repeat
    	action "if true" { "repeat" };

    	action "push data" {
    		register: 1;
    	};
    	action "set variable";
    };

    sequence "main"
    {
    	frame_rate = 30;
    	screen;

    	set background color { sswf.col.cyan };

    	// The shapes
    	top_left;
    	bottom_right;
    	active_area;

    	// The sprites
    	tl;
    	br;
    	area;
    	aa1;
    	aa2;

    	// The font & text
    	font_selection;
    	button_text;

    	do action {
    		action "push data" {
    			string: "button_label";
    			string: "</p>";
    			string: "<p align=\"center\">";
    			string: "label";
    		};
    		action "get variable";
    		action "concatenate string";
    		action "swap";
    		action "concatenate string";
    		action "set variable";		// button_label = <p ...> + label + </p>
    		action "stop";
    	};

    	// The button
    	my_button;

    	place object {
    		depth: 1;
    		id: my_button;
    	};

    	// there isn't a way to stop this animation since it's
    	// all happening in the sprite object - thus the main
    	// movie doesn't need more than one frame
    	// P.S. the stop is propbably useless
    	show frame;
    };