I'm working on a tool for compiling TypeScript to SWF. I didn't get on the transformer for example yet, but I wanted to reused a little bit of boilerplate code from another abc. What I'm doing is simply contributing ABCs from a SWC to the output SWF, but does that work?
// ...
public mergeSWF(file: Buffer | string) {
let swf = SwfReader.readSync(file);
let symbolClasses = swf.tags.filter(tag => tag.code == SwfTagCode.SYMBOL_CLASS);
let reassignedCharTagIds = new Map<number, number>();
for (let tag of swf.tags) {
if (tag.code == SwfTagCode.DO_ABC) {
this.swfTags.push(tag);
} else if (tag.code == SwfTagCode.DEFINE_BINARY_DATA) {
// re-assign the character tag ID if already used.
let binaryData = new SwfReader(ByteArray.from(tag.data!)).defineBinaryData();
let prevTag = binaryData.tag;
binaryData.tag = this.swfAlreadyUsedCharTagIds.has(binaryData.tag) ? this.nextSWFCharTagId() : binaryData.tag;
this.swfAlreadyUsedCharTagIds.add(binaryData.tag);
reassignedCharTagIds.set(prevTag, binaryData.tag);
let newData = new SwfWriter();
newData.ui16(binaryData.tag);
newData.ui32(0);
newData.binary(binaryData.data);
tag.data = newData.toNodejsBuffer();
}
}
for (let symbolClass of symbolClasses) {
// re-assign the character tag IDs
for (let symbol of symbolClass.symbols!) {
symbol.id = reassignedCharTagIds.get(symbol.id)!;
}
this.swfTags.push(symbolClass);
}
}
Can a DoABC in a SWF refer to another DoABC in the same SWF without merging the bytecodes (e.g. constant pool)?
Example:
lib.abcq.b::C
app.abcMainrefers toq.b::Cfromlib.abc
Is this expected to work on the AVM2, given that lib.abc appears before app.abc?