Animate JSFL Rebuild
Overview
End-to-end workflow for reconstructing a legacy Flash animation inside Adobe Animate 2024 from (a) a tutorial/lesson document plus source assets and (b) a compiled reference SWF. The deliverable is a JSFL generator that produces a finished .fla, plus a self-contained package a non-technical recipient can run in Animate with no Python/tooling.
Always prefer measured facts from the reference SWF over assumptions. Every JSFL behavior below was empirically verified on Animate 2024 (WIN 24,0,11,4); re-probe when the version differs.
Workflow
Phase 0 — Preflight (5 min)
- Verify Animate CLI works:
"<Animate dir>/Animate.exe" "<script>.jsfl" -AlwaysRunJSFL. - Check
python+ Pillow (setPYTHONPATHto the machine's site-packages whensys.prefixmisresolves), Java/FFDec, a headless rasterizer (resvg). - Read
scripts/jsfl_probe.jsfl, run it once in Animate, and read the generated probe log. It confirms document type, frame semantics, layer/folder behavior, symbol creation and export in the current build.
Phase 1 — Recon and extraction
- Parse the reference SWF header (stage, fps, frame count) before anything else — it is the acceptance baseline. Use
scripts/validate_swf.py --swf <ref.swf> --header-only. - Export the reference to XFL with FFDec:
java -jar ffdec.jar -export xfl <outdir> <ref.swf>. The XFLDOMDocument.xml+LIBRARY/Symbol *.xmlgive authoritative layer structure, keyframes, matrices, alphas, blend modes, filters, frame scripts and sound names. - Do not use
-export spritefor artwork: it renders sprites as white outlines on black. Use XFL shape XML (edge strings) or FFDec-export shape -format shape:svg, or render main-timelineframeexports as visual ground truth. - Mine the tutorial document only for names, techniques and numbers the SWF cannot express; reconcile conflicting numbers in favour of the SWF when validating visually.
- Inventory source assets with Pillow (dimensions/alpha). Identify which library symbols wrap which bitmaps.
Phase 2 — Choose the reconstruction strategy
Read references/reconstruction-strategies.md for the full decision matrix. Short version:
- Scriptable as-is: stage properties, layers/folders, bitmap imports, symbol instances, classic motion/shape tweens, alpha/advanced color, blend modes, sound-on-frame, frame
stop(). - Not scriptable (plan a workaround up front):
- Eraser-based stroke isolation and hand-drawn shape tweens → bake per-frame sequences from the reference geometry or frames.
- Element filters (blur/glow) → pre-bake blurred PNGs with Pillow.
- SVG import → always opens a modal dialog; rasterize at 4× instead.
- Animated GIF import → frame content silently comes out transparent (palette/transparency handling); do not rely on it.
- Layer masks → only dependable as one isolated mask/child pair; set
layerType="mask"before adding any content, associate child viaparentLayer, and wrap every pair in its own symbol.
- Most robust fallback for reveal/writing animations: sprite sheet + per-frame AS3 offsets — one bitmap placement per sequence, then per-frame
s.x/s.yscripts. See the strategy reference for grid math.
Phase 3 — Build the JSFL generator
Follow references/jsfl-api-notes.md. Architecture that scales:
- Config block: resolve paths from
fl.scriptURI(formatfile:///C|/...→ normalize), never hardcode user directories. L()/T()logging helpers writing to a file viaFLfile.write(..., true)(append) — one line per step; never rely on traces.- Helpers:
findLayerLast,ensureKey(select layer+frame first),placeItemwith 1–4 retries, copy-keyframe mode for repeated keys,artSym,sheetAnimMC, folder/mask recipes, library-name normalization. - Build order: import assets → build symbols (bitmaps → composite MCs → animation MCs) → create main scene skeleton (folders/children) → fill layer contents → set folder/mask/guide relations → sound/AS → save.
- Prefer one
addItemToDocumentper layer (or per sequence) andinsertKeyframecopies afterwards; each placement can trigger a blocking modal on some installs.
Phase 4 — Run and debug loop
- Run headless-ish via CLI; watch the log file, not the GUI.
- If blocked, use
scripts/animate_dialog_helper.ps1(dev-only): brings any Animate dialog topmost/foreground and presses Enter. Never ship it. - Keep scripts off long busy loops; Animate's watchdog asks "script running a long time — continue?" and interrupts publish.
- Publish is asynchronous: closing the doc/
fl.quit()right afterpublish()leaves a truncated SWF (~50 bytes). Reopen the saved FLA, publish, then keep the app open and poll file size; for recipients, documentShift+F12instead.
Phase 5 — Verify and package
- Structural check: unzip the
.fla(XFL zip), assert layer count, frame counts of animation symbols, frame ActionScript, soundName on the music layer. - Visual check: render key frames from the produced SWF and the reference with FFDec
-export frame; compare side-by-side with Pillow (scripts/validate_swf.pysupports both). - Accept only when stage/fps/frames match and reveal/timing motions match the reference frames you sampled.
- Handoff package per
references/handoff-package.md:source/ assets/ data/ <script>.jsfl README.md <prebuilt>.fla, relocatable, no dev helpers/logs, human runs it from the Scripts menu and clicks dialogs.
Critical rules (hard-won)
- Frame APIs are 0-based:
insertKeyframe(n),setSelectedFrames(n,n),frames[n].startFrame. timeline.currentFramereadback is unreliable; alwayssetSelectedLayers+setSelectedFrames.- Select the target layer and frame before
insertBlankKeyframe/draw operations; stale selection silently puts content on the wrong layer. - Animate sanitizes
-→_(and sometimes.→_) in layer and symbol names; resolve library items by normalized name (replace(/[-_.]/g,"")). - Mask type must be set immediately after creating the mask layer, before content; mask layers clip everything below them — isolate pairs in their own symbols.
- Folder children: select the folder,
addNewLayer(name,"normal",false); create bottom→top order reversed; setparentLayerexplicitly. importFilerequires afile:///URI with percent-encoded non-ASCII; plainC:/...paths fail with "invalid URI".addItemToDocumentfor symbol instances uses the registration point as the placement point; raw bitmaps use their center untilx/yare assigned.- A corrupt/truncated SWF after publish means the script ended/quitted before the async publish finished — reopen + publish + poll, or hand off manual publish.
Resources
references/jsfl-api-notes.md— verified JSFL object/property behavior and ready-to-use helper recipes.references/reconstruction-strategies.md— decision matrix, XFL edge-string grammar, mask/filter/eraser workarounds, sprite-sheet + AS3 pipeline math, coordinate reconciliation.references/verification.md— SWF header parsing, FFDec frame rendering, PIL comparison, XFL structural assertions, acceptance checklist.references/handoff-package.md— relocatable script header, package layout, recipient README template, publish caveats.scripts/jsfl_probe.jsfl— dependency-free capability probe; writes a log beside itself and quits.scripts/animate_dialog_helper.ps1— dev-only watchdog/dialog helper (-Seconds Nto self-terminate); never ship.scripts/validate_swf.py— header check plus optional reference-vs-generated frame comparison.