SWFAction

$a = new SWFAction(script);

Compiles the given script into an SWFAction object.

The script syntax is based on the C language, but with a lot taken out- the SWF bytecode machine is just too simpleminded to do a lot of things we might like. For instance, we can't implement function calls without a tremendous amount of hackery because the jump bytecode has a hardcoded offset value. No pushing your calling address to the stack and returning- every function would have to know exactly where to return to.

So what's left? The compiler recognises the following tokens:

break
for
continue
if
else
do
while
There is no typed data; all values in the SWF action machine are stored as strings.

There are no bitwise operators, and no modulus (%).

The following string operations are defined:

& - concatenation
=== - string equality
!== - string not-equals
<=> - string comparison
For example, 1 == 1.0 is true, but 1 === 1.0 is false.

The following functions can be used in expressions:

time()

Returns the number of milliseconds (?) elapsed since the movie started.

random(num)

Returns a pseudo-random number in the range 0-num.

length(expr)

Returns the string length of the given expression.

int(number)

Returns the given number rounded down to the nearest integer.

concat(expr, expr)

Returns the concatenation of the given expressions. (Also can use &.)

ord(expr)

Returns the ASCII code for the given character

chr(num)

Returns the character for the given ASCII code

substr(string, location, length)

Returns the substring of length length at location location of the given string string.
Additionally, the following commands may be used:

duplicateClip(clip, name, depth)

Duplicate the named movie clip (aka sprite). The new movie clip has name name and is at depth depth.

removeClip(expr)

Removes the named movie clip.

trace(expr)

Write the given expression to the trace log. Doubtful that the browser plugin does anything with this.

startDrag(target, lock, [left, top, right, bottom])

Start dragging the movie clip target. The lock argument indicates whether to lock the sprite to the mouse- use 0 (false) or 1 (true). Optional parameters define a constraint area for the dragging.

stopDrag()

Stop dragging my heart around. And this movie clip, too.

callFrame(expr)

Calls a sprite frame as a function. expr should be "/sprite:frame".

It's a damn weird hack on MM's part, but it'll let us make real function calls in Ming. All we have to do is implement a stack in the variable space, and translate function declarations into named frames in a "code" sprite. As they say, it's so crazy it just might work.

getURL(url, target, [method])

Load the given url into the named target. The target argument can be a frame name (I think), or one of the magical values "_level0" (replaces current movie) or "_level1" (loads new movie on top of current movie). The optional method argument can be post or get if you want to submit variables back to the server.

nextFrame()

Go to the next frame.

prevFrame()

Go to the last (or, rather, previous) frame.

play()

Start playing the movie.

stop()

Stop playing the movie.

toggleQuality()

Toggle between high and low quality.

You can also set the quality with this.quality = 0; or this.quality = 1;.

stopSounds()

Stop playing all sounds.

gotoFrame(num)

Go to frame number num. Frame numbers start at 0.

gotoFrame(name)

Go to the frame named name. Set the current frame's label with the SWFMovie::labelFrame or SWFSprite::labelFrame commands.

setTarget(expr)

Sets the context for action. For instance, to make the top-level sprite named "box" go to its frame #4, do:
setTarget('/box'); gotoFrame(4);
And there's one weird extra thing. The expression frameLoaded(num) can be used in if statements and while loops to check if the given frame number has been loaded yet. But I haven't actually tested this yet, so I'll be surprised if it works.

Properties
Sprites have properties. An action in a sprite can access the sprite as this instead of giving a full path name to the sprite.

Here's the properties you can read and set:

x
y
xScale
yScale
currentFrame - (read-only)
totalFrames - (read-only)
alpha - transparency level
visible - 1=on, 0=off (?)
width - (read-only)
height - (read-only)
rotation
target - (read-only) (???)
framesLoaded - (read-only)
name
dropTarget - (read-only) (???)
url - (read-only) (???)
highQuality - 1=high, 0=low (?)
focusRect - (???)
soundBufTime - (???)
So, setting a sprite's x position is as simple as /box.x = 100;. Why the slash in front of the box, though? That's how flash keeps track of the sprites in the movie, just like a unix filesystem- here it shows that box is at the top level. If the sprite named box had another sprite named biff inside of it, you'd set its x position (relative to its parent sprite) with /box/biff.x = 100;.

The "get property" action doesn't seem to work, though, which means you have to keep all your numbers in external variables as in the following example. (Can't just do /ball.x += 5; If anyone would care to point out what I'm missing here, I'd be ever so grateful.)

Here's some very simple example code which doesn't explain much at all.


All content Copyright (C) 2000 Opaque Industries except where noted otherwise.