Created
December 26, 2010 17:12
-
-
Save 9re/755513 to your computer and use it in GitHub Desktop.
parse down MovieClip recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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