Getting a list of Library objects?
Is there a way to access or iterate through a list of all objects exported to ActionScript from the Flash IDE? I'm looking to save myself some hassle by just iterating through selected MCs and processing them in a certain way, without knowing their names.
Thanks.
我使用这里描述的SwfClassExplorer:http://flassari.is/2008/07/swf-class-explorer-for-as3/
Not at run-time, no. You can manipulate library objects with JSFL in the IDE though: http://livedocs.adobe.com/flash/9.0/main/flash_cs3_extending.pdf. Not sure if that helps at all but perhaps you can generate code for use in your application by analyzing the library in some way.
var lib = fl.getDocumentDOM().library;
for (var i = 0; i < lib.items.length; i++)
{
var item = lib[0];
fl.trace(item.name + " " + item.getItemType());
}
Perhaps generate some code based on library objects' getItemProperty()
or getItemType()
.
Other than that, I think your best bet is to do as the others said. Create a dummy MovieClip that has each element inside of it and hide it off stage. Add a listener for "added to stage" on it and loop through its children and use "reflection" getQualifiedClassName to perform actions based on it's class or just use an instance name and a switch statement.
Lastly though, what is it exactly that you are "processing" on each of these MovieClips? Perhaps it's more of a design issue and they should all extend a common MovieClip subclass that has an "added to stage" handler added to it where you look at the MovieClip's type as it's added to your application and perform some actions in that single function. I'm working on some Localization work at work right now and this is how we handle processing multiple different clips at runtime.
This questions is somewhat similar to this one.
This is the JSFL you need to list the only the MovieClips that are exported to actionscript:
var doc = fl.getDocumentDOM();
var libItems = doc.library.items;
var libItemsNum = libItems.length;
var classesString = 'var '+doc.name.substr(0,doc.name.length-4)+'Classes = [';
var classesNum = 0;
var classes = [];
fl.outputPanel.clear();
for(var i = 0 ; i < libItemsNum; i++){
if(libItems[i].linkageExportForAS){
classes[classesNum] = libItems[i].linkageClassName;
classesNum++;
}
}
for(i = 0; i < classesNum; i++){
if(i < classesNum-1) classesString += '"'+classes[i]+'",';
else classesString += '"'+classes[i]+'"];';
}
fl.clipCopyString(classesString);
fl.trace(classesString);
It traces out the name of your exported classes as an array of strings so you can use that in with ApplicationDomain's getDefinitionByName() or flash.utils.getDefinition() . Also, it copies the traced message to the clipboard. If you save the JSFL in the Commands folder, you can set a keyboard shortcut for a bit of speed.
HTH, George
链接地址: http://www.djcxy.com/p/44562.html上一篇: ASP.net会话cookie丢失或删除
下一篇: 获取库对象列表?