Scripting API
SwfMesh exposes the same scripting surface in both engines. The only systematic difference is naming convention:
- Unity (C#) uses
PascalCase-GotoAndStop,CurrentFrame - Godot (GDScript) uses
snake_case-goto_and_stop,current_frame
This page names methods neutrally in prose and shows both spellings in the tables.
The clip model#
Every timeline is a clip, and every level of the hierarchy is the same type. The root timeline is a clip; so is a movie clip nested five levels down. They all answer the same methods, so code written against one works against any of them.
Get the root clip from the player, then walk into nested clips by instance name:
// Unity
SwfClip root = player.Clip;
SwfClip hand = player.Clip.GetClip("body").GetClip("arm").GetClip("hand");# Godot
var root: SwfClip = clip
var hand: SwfClip = clip.get_clip("body").get_clip("arm").get_clip("hand")A clip is a lightweight proxy - all state lives in the player's runtime. Don't retain one past the lifetime of the player that owns it.
Playback#
| Unity | Godot | |
|---|---|---|
| Start playing | Play() |
play() |
| Stop at current frame | Stop() |
stop() |
| Jump to frame and stop | GotoAndStop(int) |
goto_and_stop(int) |
| Jump to frame and play | GotoAndPlay(int) |
goto_and_play(int) |
| Jump to a frame label | GotoAndStop(string) / GotoAndPlay(string) |
goto_and_stop(String) / goto_and_play(String) |
| Step forward one frame | NextFrame() |
next_frame() |
| Step back one frame | PrevFrame() |
prev_frame() |
Frame numbers are 1-based, matching Flash. Stepping wraps at either end.
State#
| Unity | Godot | |
|---|---|---|
| Currently playing | Playing |
playing |
| Current frame | CurrentFrame |
get_frame() |
| Total frames | FrameCount |
get_frame_count() |
| Current frame label | - | get_current_frame_label() |
| All frame labels | - | get_frame_labels() |
Hierarchy#
| Unity | Godot | |
|---|---|---|
| Root clip | player.Clip |
clip |
| Nested clip by name | GetClip(string) |
get_clip(String) |
| Child instance names | GetChildNames() |
get_child_names() |
| This clip's dot-path | GetPath() |
get_path() |
Paths are dot-separated instance names - body.arm.hand.
Transform overrides#
Override a clip's placement within its parent, without stopping its animation. Setting one component overrides only that component.
| Unity | Godot | |
|---|---|---|
| Position | X / Y |
set_x() / set_y() · get_x() / get_y() |
| Rotation (degrees) | Rotation |
set_rotation() / get_rotation() |
| Scale | ScaleX / ScaleY |
set_scale_x() / set_scale_y() · get_scale_x() / get_scale_y() |
| Clear all overrides | ResetTransform() |
reset_transform() |
Rotation is clockwise degrees, following the Flash convention. These are no-ops on the root clip.
Injecting content#
Attach one SWF player into a named clip instance of another, so it renders at that clip's depth and inherits its animated transform. Attachment takes SWF players - an ordinary engine object is rejected.
| Unity | Godot | |
|---|---|---|
| Attach | AddChild(...) |
add_child(...) |
| Detach | RemoveChild(...) |
remove_child(...) |
The behaviour that comes with it is in Plugin Features.
Events#
Events start in the SWF. You put ActionScript on a keyframe in Flash / Animate exactly as you always have; SwfMesh reads it at import, bakes it to data, and delivers it to your game code as an ordinary engine signal or C# event. Nothing is interpreted at play time - see Supported Features for which actions are read and what that rules out.
What you author#
Put this on a keyframe of the timeline you want the event on - the root timeline or any nested clip:
// AS3 - on a keyframe
dispatchEvent(new Event("footstep"));
stop();The string you pass to Event is the name your game code receives. Anything is fine -
footstep, spawn_projectile, dialogue_beat_2.
Playback control is read from the same keyframes, in both AS3 and AS2:
// AS3
stop();
play();
gotoAndStop(12);
gotoAndPlay("intro"); // frame labels work too// AS2 - on a keyframe
stop();
gotoAndPlay("intro");Custom events must be authored as AS3. AS1/AS2 has no standard dispatchEvent, so
only stop / play / gotoAndStop / gotoAndPlay are read from an AS2 SWF. If you
need custom events in an AS2 file, dispatch them from game code instead.
Frame 1 of every scripted timeline runs once on the first tick, before anything
advances - matching Flash. Connect your listeners before then (Godot _ready, Unity
Awake / OnEnable); an event with no listener at emit time is dropped, not buffered.
What arrives#
| Signal / event | Godot | Unity |
|---|---|---|
A frame's dispatchEvent fired |
event_dispatched(name, clip_path) |
OnEvent(name, clipPath) |
| A timeline reached its end | animation_complete(clip_path) |
OnAnimationComplete(clipPath) |
| The active timeline's frame changed | frame_changed(frame) |
- |
clip_path is the dot-path of the clip that fired it; the active timeline reports "".
Unity's two also exist as UnityEvents (onEvent, onAnimationComplete) so a designer
can wire one up in the inspector without writing code.
# Godot
func _ready():
$SwfNode3D.event_dispatched.connect(_on_event)
$SwfNode3D.animation_complete.connect(func(clip_path): print("done: ", clip_path))
func _on_event(name: String, clip_path: String):
if name == "footstep":
$AudioStreamPlayer.play()// Unity
void OnEnable()
{
player.OnEvent += (name, clipPath) => { if (name == "footstep") PlayFootstep(); };
player.OnAnimationComplete += clipPath => Debug.Log($"done: {clipPath}");
}Both engines also show the extracted table read-only, one line per action, in a Frame
Scripts section on the asset and on the player - so you can confirm what a .swf
actually carries without running it.
Player-level properties#
Beyond the clip surface, the player component/node carries configuration - the source asset, which library symbol to use as the root timeline, frame-rate source, layering mode, scale and pivot, audio and hitbox options. These are inspector properties in both engines and are documented in the inspector tooltips.
See also#
- Plugin Features - what those properties actually control
- MovieClip Library - selecting and switching which clip plays
- Hit Boxes - hitbox events and the active-set query
- Supported Features - what of the SWF format renders