Project
A loaded Scratch project (.sb3). An sb3 is a zip holding a project.json
description plus the costume/sound asset files it references. Project is the
entry point: load bytes, edit declaratively through Stage and
Sprite, then save back to bytes.
Instance fields
A Project holds exactly the two things an sb3 zip contains.
project.json
- Type:
object
The parsed project.json. Fully mutable; every accessor on Project,
Target and the asset classes reads and writes through it. You can reach into it
directly for fields the typed API doesn't cover.
project.assets
- Type:
Map<string, Uint8Array>
Asset bytes keyed by md5ext (<md5>.<ext>, e.g. b7f1cf69….wav). This is the
set of files written alongside project.json when you save().
Static methods
Project.load(data)
data:Uint8Array | ArrayBuffer | Buffer— the sb3 zip bytes.- Returns:
Promise<Project> - Throws: if
project.jsonis missing from the zip.
Parse a project from the raw bytes of an .sb3 file. The zip is decompressed,
project.json is parsed, and every other file is read into
project.assets.
Project.create()
- Returns:
Project
Create a new, empty project containing just a bare stage (named Stage, with
default volume, tempo and video settings). The starting point for
building a project from scratch.
Accessors
project.stage
- Type:
Stage(getter)
The project's single stage.
project.sprites
- Type:
Sprite[](getter)
All non-stage targets, in array order.
project.targets
- Type:
Array<Stage | Sprite>(getter)
Every target, the stage included.
project.meta
- Type:
ProjectMeta(getter)
The project's meta block:
project.monitors
- Type:
object[](getter)
The raw monitors array — the on-stage variable/list watchers. Exposed raw;
mutate directly to add or change a watcher.
project.extensions
- Type:
string[](getter)
Ids of enabled extensions (e.g. pen, music).
Methods
project.sprite(name)
name:string- Returns:
Sprite| undefined
Find a sprite by name. Does not match the stage.
project.target(name)
Find any target — sprite or stage — by name.
project.addSprite(name, props?)
name:string— must be unique among sprites.props:object(optional) — initial property overrides (x,y,size,direction,visible, …).- Returns:
Sprite— the new sprite. - Throws: if a sprite with that name already exists.
Add a new, empty sprite. It is placed on a layer above every existing target. It
starts with no costumes, so add at least one with
addCostume before opening the project in an editor.
project.removeSprite(nameOrSprite)
nameOrSprite:string |Sprite- Returns:
boolean—trueif a sprite was removed.
Remove a sprite by name or instance. Costume and sound bytes the sprite solely owned are dropped; assets shared with another target are kept.
project.save(options?)
options.compressionLevel:number(default6) — DEFLATE level, 1–9.- Returns:
Promise<Uint8Array>— the sb3 zip bytes.
Serialize the project back into .sb3 bytes: project.json is stringified and
written, then every entry of project.assets is added, and the
whole thing is DEFLATE-compressed.
Asset cleanup
Internally, removing or replacing media calls a private _maybeDropAsset(md5ext)
helper that deletes an asset's bytes only if no costume or sound anywhere still
references them. You never call it directly, but it is why removing one of two
sprites that share an image does not break the other.
Constructor
json:object— a parsedproject.json.assets:Map<string, Uint8Array>(default empty) — asset bytes keyed bymd5ext.
Prefer Project.load or Project.create.
Construct directly only when you already hold a parsed project.json and its
asset bytes.