场景扫描函数
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-11
场景扫描函数,可以扫描场景或某一影片剪辑中的所有对象,并通过XML对象返回结果!使用XML是为了更好的和Tree组件结合,而Tree组件则可以很好的体现出层次关系! 点击浏览该文件 (纯AS扫描) 点击浏览该文件 函数: //扫描主函数,用于扫描 //mc :要扫描的影片剪辑 name :XML对象的父节点名称 function scan(mc:MovieClip, name:String):XML { mc = (mc == undefined) ? _root : mc; name = (name == undefined) ? "Movie" : name; var children:Array = []; children[0] = [mc]; var xml:XML = new XML(); var xmls:Array = []; xmls[0] = [xml.addTreeNode(name)]; while (children.length>0) { children.push(new Array()); xmls.push(new Array()); for (var i in children[children.length-2][0]) { if (execpt(children[children.length-2][0], i)) { if (typeof children[children.length-2][0][i] == "movieclip") { children[children.length-1].push(children[children.length-2][0][i]); xmls[children.length-1].push(xmls[children.length-2][0].addTreeNode(i,getData(children[children.length-2][0], i))); }else{ xmls[children.length-2][0].addTreeNode(i,getData(children[children.length-2][0], i)) } } } children[chlidren.length-2].splice(0, 1); xmls[chlidren.length-2].splice(0, 1); if (children[chlidren.length-2].length == 0) { children.splice(chlidren.length-2, 1); xmls.splice(chlidren.length-2, 1); } if (children[children.length-1].length == 0) { children.pop(); xmls.pop(); } } return xml; } //扫描排除函数,用于排除一些无须扫描的对象 //mc :要扫描的影片剪辑 name :XML对象的父节点名称 //excepts :当使用任何一个组件是,会向每个影片剪辑中添加的无用对象 function execpt(mc:MovieClip, name:String):Boolean { var result:Boolean = true; var excepts:Array = ["setStyle", "notifyStyleChangeInChildren", "changeColorStyleInChildren", "changeTextStyleInChildren", "getStyle", "getStyleName", "_getTextFormat", "__getTextFormat", "destroyObject", "createEmptyObject", "createClassObject", "createObject", "createLabel", "getTopLevel", "buildDepthTable", "getDepthByFlag", "shuffleDepths", "findNextAvailableDepth", "setDepthBelow", "setDepthAbove", "setDepthTo", "createChildAtDepth", "createClassChildAtDepth", "tabEnabled", "tabChildren", "focusManager", "height", "width", "$version", "reserved", "focusManager"]; for (var i in excepts) { if (name == excepts[i]) { result = false; } } return result; } //扫描书局函数,用于指定扫描时需要获取的有关信息 //mc :要扫描的影片剪辑 name :XML对象的父节点名称 function getData(mc:MovieClip, name:String):Object { return {x:mc[name]._x,y:mc[name]._y} } 使用时,直接调用 scan(_root,"main")即可!(可以修改execpt函数和getData函数) 关键词:扫描 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: 鼠标跟随之粒子扩散效果下一篇: 滑动杆控制的图片缓冲效果
关于场景扫描函数的所有评论