use SWF::Element;
use SWF::File;

$filename = $0;
$filename = $1 if $filename =~ /(\w+).pl$/;

$new = SWF::File->new("$filename.swf", Version => 4);

$Xmax = 2040; # 4800;
$Ymax = 2040; # 6400;

$expect_output
 = "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz"
 . "\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nF"
 . "izzBuzz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43"
 . "\n44\nFizzBuzz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nF"
 . "izz\n58\n59\nFizzBuzz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz"
 . "\n71\nFizz\n73\n74\nFizzBuzz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFiz"
 . "z\nBuzz\n86\nFizz\n88\n89\nFizzBuzz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n"
 . "98\nFizz\nBuzz";

$expect_output = "Hello world!\n";

# fizzbuzz.swf  SWF header

$new->FrameSize(0, 0, $Xmax, $Ymax);
$new->FrameRate(12.0);
# $new->FrameCount(1);

# fizzbuzz.swf  SWF tags

SWF::Element::Tag::SetBackgroundColor->new(
    BackgroundColor => SWF::Element::RGB->new(
        Red => 0x33,
        Green => 0x33,
        Blue => 0x33,
    ),
)->pack($new);

SWF::Element::Tag::DoAction->new(
    Actions => SWF::Element::Array::ACTIONRECORDARRAY->new([
        SWF::Element::ACTIONRECORD::ActionPush->new(
            Tag => 'ActionPush',
            DataList => SWF::Element::Array::ACTIONDATAARRAY->new([
                SWF::Element::ACTIONDATA::String->new("o"),
                SWF::Element::ACTIONDATA::String->new($expect_output),
            ]),
        ),
        SWF::Element::ACTIONRECORD->new(
            Tag => 'ActionSetVariable',
        ),
        SWF::Element::ACTIONRECORD->new(
            Tag => 'ActionEnd',
            LocalLabel => "EXIT",
        ),

    ]),
)->pack($new);

SWF::Element::Tag::DefineEditText->new(
    CharacterID => 1,
    Bounds => SWF::Element::RECT->new(
        Xmin => 20, 
        Ymin => 20,
        Xmax => $Xmax - 40, 
        Ymax => $Ymax - 40,
    ),
    Multiline => 1,
    ReadOnly => 0,
    WordWrap => 1,
    Border => 1,
    VariableName => "o",
    HasFont => 0,
    HasTextColor => 0,
    HasMaxLength => 0,
    HasLayout => 0,
    HasText => 0,
)->pack($new);

SWF::Element::Tag::PlaceObject->new(
    Depth => 1,
    CharacterID => 1,
    Matrix => SWF::Element::MATRIX->new(
        TranslateX => 0,
        TranslateY => 0,
    ),
)->pack($new);

SWF::Element::Tag::ShowFrame->new(
)->pack($new);


SWF::Element::Tag::End->new(
)->pack($new);

# $new->compress;
$new->close;

