Question

I need to convert timeline animations in a FLA into AS3 code (through XML, probably). The problem is that there are literally hundreds of layers and thousands of frames.

Though I understand JSFL's structure, I am cannot find the "guides" animations by looping down into the timeline->layer->frame. Using curFrame.isMotionObject() is always false.

Here is a sample of what I am trying to do:

/* Gets all motions in all motion objects and exports to a file. */
fl.outputPanel.clear();

//store max layers/frames
var fcnt = fl.getDocumentDOM().getTimeline().frameCount;
var lcnt = fl.getDocumentDOM().getTimeline().layerCount;
fl.trace( "fl.getDocumentDOM().getTimeline().frameCount = " + fcnt );
fl.trace( "fl.getDocumentDOM().getTimeline().layerCount = " + lcnt );

//store pre-run layers/frames:
var origFr = fl.getDocumentDOM().getTimeline().currentFrame;
var origLyr = fl.getDocumentDOM().getTimeline().currentLayer;
fl.trace( "fl.getDocumentDOM().getTimeline().currentFrame = " + origFr );
fl.trace( "fl.getDocumentDOM().getTimeline().currentLayer = " + origLyr );

var totout = 0;
var curFrm;
var curl = origLyr;
var curf = origFr; 
var outstr = "";

for (curf = 0; curf < fcnt; curf++)
{
    // have the IDE go into the current frame:
    fl.getDocumentDOM().getTimeline().currentFrame = curf;

    // removed to test one layer only
    //for (curl = 0; curl < lcnt; curl = lcnt) // curl++) // curl = lcnt)
    //{

        // have the IDE go into the current layer:
        fl.getDocumentDOM().getTimeline().currentLayer = curl;

        if(curf > fl.getDocumentDOM().getTimeline().layers[curl].frames.length)
            break;

        curFrm = fl.getDocumentDOM().getTimeline().layers[curl].frames[curf];

        //this is always false. . . why?
        if (
            curFrm.isMotionObject() 
            //&& curFrm.hasMotionPath()
        ){
            totout++;
            //curFrm.selectMotionPath(true);
        }
        else{
            outstr += "There is no motion path\n";
        }

        //for testing:
        break;
    //}
    //for testing:
    //break;
}

//reset layers/frames back to pre-run status:
fl.getDocumentDOM().getTimeline().currentFrame = origFr;
fl.getDocumentDOM().getTimeline().currentLayer = origLyr;

fl.trace(outstr);
fl.trace("totout = " + totout);
Was it helpful?

Solution

You can use the Export Motion XML command, which you can call from jsfl via:

fl.runScript(fl.configURI + 'Javascript/MotionXML.jsfl', 'exportMotionXML');

As far as I remember the Classic Tween XML format is different from the Motion Tween XML format. The Motion XML features is quite handy and underused. You can use copyMotionXML as well and handle the XML in JSFL as the JS engine supports E4X.

Alternatively, if you're happy with the Animator/AnimatorFactory classes from the fl.motion package, you can do this:

fl.runScript(fl.configURI + 'Javascript/MotionXML.jsfl', 'copyMotionAsAS3');

Note that the default tween classes are slower than other tween engines, like TweenLite, and you also might need to use a timer for the duration of the tween to work out when a tween is finished, so you can gain actionscript access to the tweened object again.

I've used the MotionXML feature a bit at work for the AudiA8 site we did as we had to match some interactivity over some beautiful renders from The Mill and I wrote an importer for Mocha Keyframes to Flash timeline using this feature.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top