#!/usr/bin/perl -w
use strict;

use SWF qw(:ALL);
use SWF::Constants qw(:Button :Text);

SWF::setScale(1.0);

# sprite has one letter per frame */

my $p = new SWF::Sprite();
$p->add(new SWF::Action("stop();"));

my $chars = "abcdefghijklmnopqrstuvwxyz".
            "1234567890!@#$%^&*()_+-=/[]{}|;:,.<>?`~";

my $f = new SWF::Font("_sans");

my $i;
for(my $n=0; $n<length($chars); ++$n)
{
  my $c = substr($chars, $n, 1);

  $p->remove($i) if( $i );
  my $t = new SWF::TextField();
  $t->setFont($f);
  $t->setHeight(240);
  $t->setBounds(600,240);
  $t->align(SWFTEXTFIELD_ALIGN_CENTER);
  $t->addString($c);
  $i = $p->add($t);
  $p->labelFrame($c);
  $p->nextFrame();
}


# hit region for button - the entire frame */

my $s = new SWF::Shape();
$s->setRightFill($s->addFill(0, 0, 0));
$s->drawLine(600, 0);
$s->drawLine(0, 400);
$s->drawLine(-600, 0);
$s->drawLine(0, -400);


# button checks for pressed key, sends sprite to the right frame */

my $b = new SWF::Button();
$b->addShape($s, SWFBUTTON_HIT);

for(my $n=0; $n<length($chars); ++$n)
{
  my $c = substr($chars, $n, 1);
  $b->addAction(new SWF::Action("

  setTarget('/char');
  gotoFrame('$c');

    "), SWFBUTTON_KEYPRESS($c));
}

my $m = new SWF::Movie();
$m->setDimension(600,400);
$i = $m->add($p);
$i->setName('char');
$i->moveTo(0,80);

$m->add($b);

$m->save("test.swf");
