NAME
SWF::Builder::ActionScript - SWF ActionScript object.
SYNOPSIS
$mc->frame_action(1)->compile( <<AS_END );
function move_mc(dx) {
this._x += dx;
}
AS_END
my $mc_i = $mc->place;
$mc_i->on('KeyPress', '<Left>')->compile('move_mc(-5)');
$mc_i->on('KeyPress', '<Right>')->compile('move_mc(5)');
$mc_i->on('EnterFrame')->r_rotate(15);
DESCRIPTION
SWF::Builder::ActionScript supports some simple actions and compiling ActionScript compatible with FlashMX.
Constructors
Methods for movie clip to create a frame action and a clip action. These return an SWF::Builder::ActionSctipt object.
- $as = $mc->frame_action( $frame )
-
creates a frame action.
- $as = $mc_i->on/onClipEvent( $event [, $key] )
-
creates a clip action. See SWF::Builder::MovieClip for details of the events.
Simple actions
These method add some simple actions to $as and return $as itself.
- $as->gotoAndPlay( $frame )
-
tells the flash player to go to $frame.
- $as->gotoAndStop( $frame )
-
tells the flash player to go to $frame and stop playing.
- $as->play
-
tells the flash player to play the movie clip.
- $as->stop
-
tells the flash player to stop playing the movie clip.
- $as->setProperty( $property, $value )
-
sets a movie clip property.
- $as->moveto( $x, $y )
-
moves the movie clip to ($x, $y).
- $as->r_moveto( $dx, $dy )
-
moves the movie clip to (current X + $dx, current Y + $dy).
- $as->rotate( $r )
-
rotates the movie clip toward $r degree absolutely.
- $as->r_rotate( $dr )
-
rotates the movie clip to +$r degree right.
- $as->scale( $xscale [, $yscale] )
-
magnifies/reduces the movie clip.
- $as->show
-
shows the movie clip.
- $as->hide
-
hides the movie clip.
- $as->tellTarget( $target, \&actionsub )
-
changes the target movie clip for actions in &actionsub. $target is a target path string or a named movie clip instance. &actionsub is called with an ActionScript object whose target is changed. For example,
$mc_i->on('Press')->tellTarget( $mc_i2, sub { shift->r_rotate(15); });
rotates $mc_i2 to 15-degree right when $mc_i is clicked.
Compiler
SWF::Builder::ActionScript has a FlashMX-compatible compiler for complex actions.
- $as->compile( $script_text [, %options] )
-
compiles $script_text. Options are as follows:
- Optimize => $num
-
controls optimization.
bit 0: peephole optimization 1: calculate constant expressions 2: calculate math funcions with constant args and constant properties 3: evaluate a lefthand side of an assignment expression only once
Default is all on.
ATTENTION: FlashMX ActionScript compiler seems to evaluate a lefthand side of a compound assignment operator twice, while ECMA-262 provides to evaluate it once. For example, FlashMX compiles 'a[i++] += 2' as same as 'a[i++] = a[i++] + 2', which counts up i twice. Optimize bit 3 controls this. If you want the same as FlashMX, reset bit 3.
- Trace => $mode
-
tells the compiler how to compile 'trace' action.
- none
-
ignore all trace action.
- eval
-
evaluate the parameters of a trace action, but don't output anything. This is default.
- lcwin
-
output the value to another movie via a LocalConnection. You can use 'tracewindow.swf' at scripts directory as output window.
- trace
-
use ActionTrace tag.
- Warning => $level
-
sets the warning level.
0: deplicated actions. 1: useless operator in void context. 2: future reserved and other unsupported feature.
- $as->load( $script_filename [, %options] )
-
loads a script and compiles it. See compile method for %options.
Compiler bugs/features
Pragmas are not supported.
The compiler evaluates a lefthand side of an assignment expression once by default. See Optimize option.
Slow...
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.