views:

610

answers:

4

Hi, I'm writing a script to access all dynamic textfields in the library of a flash (fla) file and embed certain character sets.

I iterate through all objects looking for textfields, but It seems there are some issues when trying to access members of a group object. It does have children in the flash file, but I can see no way to access them from the Group object defined in the CS3 reference for jsfl. Group has an undocumented layer property, among others, but it seems to only contain a reference to itself.

The CS4 reference defines a members property for the Group object.

So my questions is, how do it access the children of a Group object in Flash C3 jsfl script API?

A: 

Are you sure you're working with Shapes? A shape shouldn't be able to have any actual children aside from graphics (it has a graphics property, like Sprite), which don't really count as children. They're more like a value of the graphics property.

Shape doesn't extend DisplayObjectContainer, so I'm pretty sure it can't have child display objects like a Sprite or MovieClip for example.

You should be safe skipping those if searching for TextFields.

Alex Jillard
My bad, that should have been groups
Brian Heylin
+1  A: 

Shape objects do not have children. So if you come across a Shape object in your recursion then it doesn't have any dynamic texfields inside it (or flash objects inside it as children for that matter)

What might be confusing you is thinking that grouping objects on stage makes a Shape, it does not. The "groups" of objects on stage only exists in the flash editing interface for easy editing and workflow. Once you publish they are not actually grouped in the swf/actionscript.

What may even be more confusing is that when you have multiple vector items on stage, or even in some situations bitmap items on stage, Flash will just simplify them, flattened to a single Shape object. This furthers the illusion that grouping objects creates a Shape object with each one as a child, and therefore that a Shape object could have children, but in reality all it did was flatten it all into one single Shape with those graphics drawn flat onto it, it doesn't hold any of them as individual objects. And that situation never happens with a dynamic textfield, so quite simply, if you hit a Shape object then there isn't a dynamic textfield there, move on :)

Bryan Grezeszak
A: 

You've hinted at the answer already yourself: use the members property on the shape objects. It returns an array of objects contained within, which may or may not be text objects.

You didn't specify whether you are using fl.findObjectInDocByType() to scan the document for text objects and shape (potential groups), but that would be a good idea as well.

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00004151.html

I believe the following script will trace the text value of all dynamic text fields in a FLA unless there's some nasty nested case that I missed. In any case, it should hopefully get you going. Be wary of that you need to run the script from the Commands menu in order for fl.findObjectInDocByType() not to throw an error. See the comments in the link above for more info.

// Look for text objects
var doc = fl.getDocumentDOM();
var typeToSearchFor = "text";
var results = fl.findObjectInDocByType(typeToSearchFor, doc);

for(var i = 0; i < results.length; i++)
{
    if(results[i].obj.textType == "dynamic")
    {
     doWhatever(results[i].obj);
    }
}

// Look for shapes
typeToSearchFor = "shape";
results = fl.findObjectInDocByType(typeToSearchFor, doc);

var textObjects;

for(var i = 0; i < results.length; i++)
{
    var members = results[i].obj.members;

    for(var j = 0; j < members.length; j++)
    {
     if(members[j].elementType == "text" && members[j].textType == "dynamic")
     {
      doWhatever(members[j]);
     }
    }
}


function doWhatever(textObj)
{
    fl.trace(textObj.getTextString());
}
Stiggler
Thanks Stiggler, that findObjectInDocByType() method will be a handy addition to my toolset :) But this code hits the same problem i already have, I use CS3, but the Shape class only got the 'members' property in CS4.
Brian Heylin
Oh, I completely misunderstood the problem! Fortunately, the solution is easy - just shell out some $$$ for the upgrade :)
Stiggler
+1  A: 

Just unGroup() the shapes first. Then you can run your normal "text" conversion afterwards. It shouldn't hurt the document because grouping has no real technical implications.

var doc = fl.getDocumentDOM();
var results = fl.findObjectInDocByType("shape", doc);
for (var i = 0; i < results.length; i++) 
{
    if ( results[i].obj.isGroup )
    {
     doc.selection = [results[i].obj];
     doc.unGroup();
    }
}