Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash AS3 - 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.

like image 992
Scott Avatar asked Feb 05 '10 22:02

Scott


3 Answers

I use the SwfClassExplorer described here: http://flassari.is/2008/07/swf-class-explorer-for-as3/

like image 77
Jason King Avatar answered Nov 11 '22 20:11

Jason King


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.

like image 31
typeoneerror Avatar answered Nov 11 '22 20:11

typeoneerror


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

like image 45
George Profenza Avatar answered Nov 11 '22 20:11

George Profenza