#!/usr/bin/perl -w # # Example 9-7. use strict; use SWF qw(:ALL); SWF::useSWFVersion(5); my $bitmap = new SWF::Bitmap("bitmap.dbl"); my $w = $bitmap->getWidth(); my $h = $bitmap->getHeight(); # Create a new Movie my $m = new SWF::Movie; $m->setDimension($w, $h+15); # Create the feedback TextBlock. This displays a message: "X Kb loaded" my $font = new SWF::Font("serif.fdb"); my $tf = new SWF::TextField(); $tf->setFont($font); $tf->setColor(0,0,0); $tf->setName("feedback"); $tf->setHeight(10); $tf->setBounds(300,50); my $item = $m->add($tf); $item->moveTo(0,2); # Outline the bounding box of the bitmap my $s = new SWF::Shape(); $s->setLineStyle(1, 0, 0, 0); # Black stroke drawRect($s,$w,10,0,0); $item = $m->add($s); $item->moveTo(0,15); # Create the preloader bar. It is a Sprite so that it can # encapsulate its own ActionScript code for changing the # scale based on the number of bytes loaded my $s2 = new SWF::Shape(); $s2->setLeftFill($s2->addFill(255, 0, 0)); drawRect($s2,$w,10,0,0); my $bar = new SWF::Sprite(); $item = $bar->add($s2); $bar->nextFrame(); $bar->add(new SWF::Action(<nextFrame(); $item = $m->add($bar); $item->moveTo(0,15); my $s3 = new SWF::Shape(); # Outline the bar in black $s3->setLineStyle(1, 0, 0, 0); # Black stroke drawRect($s3, $w, $h, 0, 0); $item = $m->add($s3); $item->moveTo(0,15); $m->nextFrame(); # Create a loop with ActionScript. Jump out when the whole document is loaded. $m->add(new SWF::Action(<nextFrame(); # Add the bitmap my $s4 = new SWF::Shape(); my $f = $s4->addFill($bitmap); $s4->setRightFill($f); drawRect($s4, $w, $h, 0, 0); $item = $m->add($s4); $item->moveTo(0,15); $m->nextFrame(); $m->save("preloader.swf"); exit(); # drawRect() is a helper procedure used to draw rectangles sub drawRect { my $shape = shift; my ($w, $h, $dx, $dy) = @_; $shape->movePenTo($dx, $dy); $shape->drawLine($w, 0); $shape->drawLine(0, $h); $shape->drawLine(-$w, 0); $shape->drawLine(0, -$h); }