The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SWF::Builder - Create SWF movie.

SYNOPSIS

  use SWF::Builder;

  my $movie = SWF::Builder->new
    ( FrameRate => 15,
      FrameSize => [0, 0, 400, 400],
      BackgroundColor => 'ffffff'
      );

  my $shape = $movie->new_shape   # red triangle.
    ->fillstyle('ff0000')
    ->linestyle(1, '000000')
    ->moveto(0,-11)
    ->lineto(10,6)
    ->lineto(-10,6)
    ->lineto(0,-11);

  my $instance = $shape->place;

  for (my $x = 0; $x < 400; $x++) {
      $instance->rotate(15)->moveto($x,200);
  }
  $movie->save('triangle.swf');

DESCRIPTION

SWF::Builder is a wrapper of SWF::File. It provides an easy way to create SWF6 movie.

The SWF movie consists a dictionary of character definitions and a hierarchical group of movie clips. You create a movie by following steps:

  1. create a '_root' movie by SWF::Builder->new.

  2. define characters such as shapes, fonts, texts, movieclips, and so on, by $movie->new_XXX methods.

  3. get an instance of the character by $character->place.

  4. move, scale, and rotate the instance every frame.

  5. repeat 2-4 if you need.

  6. save the whole movie by $movie->save.

'_root' movie

The '_root' movie is a top of the movie clip hierarchy. It has properties of the whole SWF movie. It also has character constructors and other methods for movie. See the next section for details.

$movie = SWF::Builder->new( [FrameRate => $rate, FrameSize => [$xmin, $ymin, $xmax, $ymax], BackgroundColor => $color] )

creates a new '_root' movie. It can take three optional named parameters. FrameRate is a frame count per second. FrameSize is a box size of frames, which is an array reference of the coordinates of top-left and bottom-right of the box in pixels. BackgroundColor is a background color of the movie. It can take a six-figure hexadecimal string, an array reference of R, G, and B value, an array reference of named parameters such as [Red => 255], and SWF::Element::RGB object.

$movie->FrameRate( $rate )
$movie->FrameSize( $xmin, $ymin, $xmax, $ymax )
$movie->BackgroundColor( $color )

sets the property. See SWF::Builder->new.

$movie->save( $filename )

saves the movie.

Character constructors

All characters must be defined before it uses.

$mc->new_shape

returns a new shape. See SWF::Builder::shape for the detail.

$mc->new_font( $fontfile [, $fontname] )

returns a new font. $fontfile is a font file name. It should be a TrueType font file (ttf/ttc). Optional $fontname is a font name referred by HTMLs in dynamic texts. It is taken from the TrueType file if not defined. See SWF::Builder::Font for the detail.

$mc->new_static_text( [$font, $text] )

returns a new static text, which is fixed by authoring and cannot be changed at playing time. See SWF::Builder::Text for the detail of a text.

$mc->new_movie_clip
$mc->new_mc

returns a new movie clip. See SWF::Builder::MovieClip for the detail.

$mc->new_gradient

returns a new gradient object. See SWF::Builder::Gradient and SWF::Builder::Shape for the detail.

$mc->new_jpeg( ... )

returns a new JPEG bitmap. See SWF::Builder::Bitmap for the detail.

$mc->new_bitmap( $type => $obj )

returns a new lossless bitmap. See SWF::Builder::Bitmap for the detail.

Other methods for movies

Here describe other common methods for root movie and movie clips.

$mc->frame_action( $frame )

returns SWF::Builder::ActionScript object for a frame action.

$mc->frame_label( $frame, $label [, $anchorflag] )

gives $label to $frame to which ActionScripts can refer. If the $anchorflag is set to 1, it is accessible as an HTML anchor.

Display instance

It is necessary to get the instance to use the defined character. Each instance has its own timeline tied to the parent movie clip and the current frame to move, to rotate, etc.

$disp_i = $char->place( [ MovieClip => $mc, Frame => $frame, above => $another_i, below => $another_i ] )

returns the display instance of the character. It can take four optional named parameters. MovieClip(MC) is a parent movie clip on which the character is placed. The movie clip must be under the same root with the movie clip in which the character is defined. If MC is not set, the character is placed on the movie clip in which it is defined. Frame is a first frame number on which the character is placed. Default is 1. You can set the relative depth of the new instance by 'above' and 'below'.

$disp_i->name( $name )

gives a name to the display instance to which ActionScripts can refer.

$fobj = $disp_i->frame( $frame )

gets the specified frame object of the display instance and sets the current frame of the display instance to $frame.

Moving, rotating, scaling, and any other matrix transforming of the display instance are handled in a frame by frame via a frame object. When a frame object is not specified, the 'current frame object' kept by the display item is used. The current frame is counted up after it is used.

$fobj/$disp_i->moveto( $x, $y )

moves the display item to ($x, $y) at the (current) frame.

$fobj/$disp_i->r_moveto( $dx, $dy )

moves the display item relatively ( to (former X + $x, former Y + $y)).

$fobj/$disp_i->scale( $xscale [, $yscale] )

magnifies/reduces the display item at the (current) frame. The scaling effect is accumulative.

$fobj/$disp_i->rotate( $angle )

rotates the display item at the (current) frame. The rotation angle is accumulative.

$fobj/$disp_i->reset

resets the rotation and scaling at the (current) frame.

$fobj/$disp_i->remove

removes the display instance from the parent movie clip at the (current) frame.

$fobj/$disp_i->matrix

gets the transformation matrix of the display instance at the (current) frame. The result is an SWF::Element::MATRIX object.

$fobj/$disp_i->frame_action
$fobj/$disp_i->frame_label( $label [, $anchorflag] )

same as those for movie clips, setting the frame number to that of the frame object.

COPYRIGHT

Copyright 2003 Yasuhiro Sasama (ySas), <ysas@nmt.ne.jp>

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.