Skip to content

Instantly share code, notes, and snippets.

@9re
Created December 26, 2010 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 9re/755513 to your computer and use it in GitHub Desktop.
Save 9re/755513 to your computer and use it in GitHub Desktop.
parse down MovieClip recursively
package
{
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.TextField;
/**
* ...
* @author kobayashi-taro
*/
public class test extends Sprite
{
public function test()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var tf:TextField = new TextField;
tf.width = stage.stageWidth;
tf.height = stage.stageHeight;
addChild(tf);
var id:String = loaderInfo.parameters.swf_id || '01';
var ldr:Loader = new Loader;
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, function _onLoaded(event:Event):void {
ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, _onLoaded);
tf.text = parseMovieClip(ldr.content as MovieClip);
});
ldr.load(new URLRequest(id+'.swf'));
}
private function parseMovieClip(mc:MovieClip, level:int = 0):String {
var numChildren:int = mc.numChildren;
var child:DisplayObject;
var childMC:MovieClip;
var childInfo:Array = [];
for (var i:int = 0; i < numChildren; ++i) {
child = mc.getChildAt(i);
if (child is MovieClip) {
childMC = child as MovieClip;
childInfo.push(
getSpaces(level << 2) + childMC.name
);
childInfo = childInfo.concat(parseMovieClip(childMC, level + 1));
}
}
return childInfo.join('\n');
}
private function getSpaces(count:int):String {
return new Array(count)
.map(function (...r):String { return " "; })
.join('');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment