Skip navigation
Stephen McGreal
Currently Being Moderated

CS5.5 JSFL: timeline.convertToKeyframes() doesn't work with motion tweens

Oct 26, 2011 6:11 AM

Tags: #bug #flash_cs5.5 #jsfl #motion_tween

I'm writing a JSFL script to export animations from Flash. I iterate through every frame in the timeline, and for each frame I go through every element in every layer, and write each Element's symbol name and matrix values out to a file. The problem is, if you've created animation using a motion tween, the exporter steps through every frame but sees the same matrix values for each Element in every frame. This is where I hit the first problem: Iterating through the timeline in this way doesn't seem to work. I can't see any way of getting the right information out for each frame.


There is a workaround: Namely, selecting all the animated layers on the timeline, and selecting "Convert to Frame by Frame animation" from the context menu. Then you run the exporter, and then you have to undo the "Convert to Frame by Frame" animation in order to continue working on the file. That's pretty messy, so I tried to automate the process, by having the export script perform the convert to frame by frame. When you perform the action, and look it up in the History window, Flash tells you that the JSFL command it used was the following:




Clearly this is nonsense. That %*d,%*d is a syntax error, as you quickly discover if you try to run this JSFL command. Anyway, I rewrote it like this, to try to indiscriminately convert every frame of every layer of the timeline:


var timeline = fl.getDocumentDOM().getTimeline();

for(var i = 0; i < timeline.layerCount; ++i) {   


    timeline.convertToKeyframes(0, timeline.frameCount);



That seems to work on everything except layers where motion tweens have been used. Layers with classic tweens (or with no movement at all) work fine, but motion tweens just don't get converted. Which is weird - manually selecting the option in the context menu works fine, but the same command in JSFL does nothing.


Any idea how I can get round this, and if/when Adobe plan on fixing it?

  • Currently Being Moderated
    May 10, 2012 7:11 PM   in reply to Stephen McGreal

    I ran into a similar problem, and I think I've found a solution that may help. If you extend the code you've written to loop through all of your layers and select them all, then do convertToKeyframes with no parameters (to default to the current selection) this seems to get around all of the bugs/quirks that the convertToKeyframes command has. I saw no less than 3 different unexpected behaviors when using the command, much like the behaviors you described. They seemed to be random bugs, but perhaps I'm simply not understanding the command.


    Either way, I think this approach is at least a work around that in my current testing has worked so far. It may work for you too. You would do something like this:


    for ( var i = 0; i < timeline.layers.length; ++i ) {

        timeline.setSelectedLayers ( i, false );  // passing false tells this command to extend the layer selection to include this layer, so we can select all layers



    timeline.convertToKeyframes ();

    Mark as:
  • Currently Being Moderated
    May 11, 2012 8:29 AM   in reply to Stephen McGreal

    I agree the command seems to be broken. My only final piece of advice is to make sure you dont have anything selected when running it. I saw the behavior change when I had an item on the stage selected before running versus not. Perhaps this is a clue as to why it malfunctions? You might be able to discover a further workaround in your script. Whatever else I'm doing in my script seems to work for now. I hope I don't run into any more issues, but if I do and I find a better solution I'll be sure to post here.

    Mark as:
  • Currently Being Moderated
    Feb 11, 2013 3:30 PM   in reply to jlytledistinctdev

    convertToKeyframes() doesn't work the same as right-clicking the Motion Object in the timeline and selecting "Convert to Frame by Frame Animation". I think you are misslead by seeing the keyframes but in reality, the frames' color are still blue (indicating they are part of a Motion Object tween, still!)


    I know this question is dated, but has anyone found the real solution to this? I'm still investigating on my end and this would be important for an exporting-tool I'm building for a client.



    Mark as:
  • Currently Being Moderated
    Apr 25, 2013 7:07 PM   in reply to Mr. Chamberlain

    I know this won't come as a comfort to you, but I'm experiencing the same thing.  I'm developing an export tool as well for my company, and I need to change motion path tweens to individual keyframes (since I can't use motion paths where this is exported to...).

    Just as you experienced, in the IDE, selecting all the frames in the tween and then right-clicking and choose "Convert to keyframes" does what I expect.  The animation path is preserved and I can now delete the motion guide path layer.


    However, try as I might, with MANY variations on how I did it, I can't get this to work in JSFL.  It converts the correct frames to keyframes, but they all are set to it's initial position at the beginning of the tween.  Infuriating.


    Adobe Flash engineers, it would REALLY be nice if you fixed this bug?  And if it's not a bug, can you explain why this doesn't function as expected?  Thanks.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points