Skip to content

Instantly share code, notes, and snippets.

@claus
Created April 14, 2011 23:51
Show Gist options
  • Select an option

  • Save claus/920852 to your computer and use it in GitHub Desktop.

Select an option

Save claus/920852 to your computer and use it in GitHub Desktop.
Dump all static text contained in a SWF (using as3swf)
package
{
import flash.display.MovieClip;
import com.codeazur.as3swf.SWF;
import com.codeazur.as3swf.tags.ITag;
import com.codeazur.as3swf.tags.TagDefineText;
import com.codeazur.as3swf.data.SWFTextRecord;
import com.codeazur.as3swf.data.SWFGlyphEntry;
import com.codeazur.as3swf.tags.TagDefineFont2;
public class DumpText extends MovieClip
{
public function DumpText()
{
// loaderInfo.bytes is a ByteArray containing the raw,
// uncompressed SWF of the document class instance.
// Parse the SWF this code is running in:
var swf:SWF = new SWF(loaderInfo.bytes);
// loop over all tags
for each(var tag:ITag in swf.tags)
{
// identify DefineText tags
if(tag is TagDefineText)
{
trace("TextField contents:");
var defineText:TagDefineText = tag as TagDefineText;
// loop over all text records in the DefineText tag
for(var i:uint = 0; i < defineText.records.length; i++)
{
var str:String = "";
var textRecord:SWFTextRecord = defineText.records[i];
// get the DefineFont tag used for this text record
var defineFont:TagDefineFont2 = swf.getCharacter(textRecord.fontId) as TagDefineFont2;
if(defineFont != null)
{
// loop over all glyph entries in the text record
for(var j:uint = 0; j < textRecord.glyphEntries.length; j++)
{
var glyphEntry:SWFGlyphEntry = textRecord.glyphEntries[j];
// the glyph entry's index property points into the glyph- and
// code table arrays of the respective DefineFont tag
str += String.fromCharCode(defineFont.codeTable[glyphEntry.index]);
}
trace(" " + i + ": \"" + str + "\" (fontId: " + textRecord.fontId + ")");
}
}
}
}
}
}
}
@devboy
Copy link
Copy Markdown

devboy commented Apr 15, 2011

Claus, du rockst!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment