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

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

SWF::setScale(1.0);

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

my $p = new SWF::Sprite();

sub label {
  my ($string) = @_;
  my $t = new SWF::TextField();
  $t->setFont($f);
  $t->addString($string);
  $t->setHeight(200);
  $t->setBounds(3200,200);
  return $t;
}
sub addLabel {
  my ($string) = @_;
  
  my $i = $p->add(label($string));
  $p->nextFrame();
  $p->remove($i);
}

$p->add(new SWF::Action("stop();"));
addLabel("NO ACTION");
addLabel("SWFBUTTON_MOUSEUP");
addLabel("SWFBUTTON_MOUSEDOWN");
addLabel("SWFBUTTON_MOUSEOVER");
addLabel("SWFBUTTON_MOUSEOUT");
addLabel("SWFBUTTON_MOUSEUPOUTSIDE");
addLabel("SWFBUTTON_DRAGOVER");
addLabel("SWFBUTTON_DRAGOUT");

sub rect {
  my ($r, $g, $b) = @_;

  my $s = new SWF::Shape();
  $s->setRightFill($s->addFill($r, $g, $b));
  $s->drawLine(600,0);
  $s->drawLine(0,600);
  $s->drawLine(-600,0);
  $s->drawLine(0,-600);
  
  return $s;
}

my $b = new SWF::Button();
  $b->addShape(rect(0xff, 0, 0), SWFBUTTON_UP | SWFBUTTON_HIT);
  $b->addShape(rect(0, 0xff, 0), SWFBUTTON_OVER);
  $b->addShape(rect(0, 0, 0xff), SWFBUTTON_DOWN);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(1);"),
              SWFBUTTON_MOUSEUP);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(2);"),
              SWFBUTTON_MOUSEDOWN);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(3);"),
              SWFBUTTON_MOUSEOVER);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(4);"),
              SWFBUTTON_MOUSEOUT);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(5);"),
              SWFBUTTON_MOUSEUPOUTSIDE);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(6);"),
              SWFBUTTON_DRAGOVER);

$b->addAction(new SWF::Action("setTarget('/label'); gotoFrame(7);"),
              SWFBUTTON_DRAGOUT);

my $m = new SWF::Movie();
$m->setDimension(4000,3000);

my $i = $m->add($p);
$i->setName("label");
$i->moveTo(400,1900);

$i = $m->add($b);
$i->moveTo(400,900);

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