6 Replies Latest reply: Apr 25, 2013 7:07 PM by RobChisholm RSS

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

    Stephen McGreal

      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:

       

      fl.getDocumentDOM().getTimeline().convertToKeyframes(%*d,%*d);

       

      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.setSelectedLayers(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?

        • 1. Re: CS5.5 JSFL: timeline.convertToKeyframes() doesn't work with motion tweens
          Stephen McGreal Community Member

          Nobody? I can't be the only person having this problem...

           

          1. Start a new Flash file in CS5.5

          2. Insert->New Symbol... Pick a suitable symbol from somewhere.

          3. Drag the symbol onto the stage

          3. Right-click on the Timeline, on some frame after the first, and select "Insert Frame"

          4. Right-click on the same frame and select "Create Motion Tween". Drag the symbol around if you want, to make it animate.

          5. Run the following script in JSFL:

           

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

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

              timeline.setSelectedLayers(i);

              timeline.convertToKeyframes(0, timeline.frameCount);

          }

           

          6. Notice how the only thing that happens is that the cursor on the timeline jumps to the last frame of the animation, and adds a dot on the last frame, but leaves the rest of the timeline exactly as it was.

           

          It works if you change step 4 to "Create classic tween", omit step 4 entirely, or if you right-click on the timeline and select "Convert to Frame By Frame Animation" rather than running the script, but that doesn't help me. I need to know how to get JSFL to correctly convert motion tween animations to keyframes.

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

            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 ();

            • 3. Re: CS5.5 JSFL: timeline.convertToKeyframes() doesn't work with motion tweens
              Stephen McGreal Community Member

              Doing things your way changes the behaviour but doesn't seem to fix my problem. If you run your script on an animation with a motion tween you end up with a dot at the point in the timeline where the playhead was, and the playhead jumps to the end of the timeline and you can clearly see that all the layers have been selected, but you still don't get the layers broken up into individual frames like you get by manually selecting Convert To Frame By Frame Animation. Even brute forcing it doesn't work. If you try this:

               

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

                  timeline.setSelectedLayers ( i, false );

              }

               

              for(var j = 0; j < timeline.frameCount; ++j) {

                        timeline.currentFrame = j;

                        timeline.convertToKeyframes ();

              }

               

              You'll get a dot on every frame but it still won't be broken down into keyframes (marked by the vertical black lines).

               

              I keep looking for a workaround (you'll notice I've been struggling with this since before October last year!) and I hope against all hope that someone will discover something, but the fact of the matter is that convertToKeyframes() is completely broken. Its behavior is inconsistent, both with the documentation and with the context menu option which it claims to be an implementation of.

              • 4. Re: CS5.5 JSFL: timeline.convertToKeyframes() doesn't work with motion tweens
                jlytledistinctdev Community Member

                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.

                • 5. Re: CS5.5 JSFL: timeline.convertToKeyframes() doesn't work with motion tweens
                  Mr. Chamberlain Community Member

                  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.

                   

                  Thanks!

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

                    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.