Skip to main content
Firewood:D
Inspiring
April 20, 2023
Answered

How to put two script commands in one file to operate

  • April 20, 2023
  • 2 replies
  • 1282 views

I got two commands using the history panel, create classic tween and delete tween,
an.getDocumentDOM().getTimeline().createMotionTween();
an.getDocumentDOM().getTimeline().setFrameProperty('tweenType', 'none');
Now I want to make these two commands into one, one click is to create, and another click is to delete, how to do it?
For example, in the my.jsfl file, put these two commands. When I use my.jsfl for the first time, add a tween, and click my.jsfl again to delete the tween.
This method is similar to the shortcut keys set for creating tweens in the software. One click in Animate is to add, and another click is to delete. without having to do two jsfl commands.
How can I achieve it, is there a formula to apply? This kind of operation is not limited to tweening, I seem to find that many commands in the history panel can be used,

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    Use the document's data API. Like this:

    var dom = fl.getDocumentDOM();
    var tl = dom.getTimeline();
    var tweenAdded = "tweenAdded";
    
    if (dom.getDataFromDocument(tweenAdded))
    {
    	tl.setFrameProperty("tweenType", 'none');
    	dom.removeDataFromDocument(tweenAdded);
    }
    else
    {
    	tl.createMotionTween();
    	dom.addDataToDocument(tweenAdded, "integer", 1);
    }

     

    I hope it helps.

     

    Regards,

    JC

    2 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    April 20, 2023

    Hi.

     

    Use the document's data API. Like this:

    var dom = fl.getDocumentDOM();
    var tl = dom.getTimeline();
    var tweenAdded = "tweenAdded";
    
    if (dom.getDataFromDocument(tweenAdded))
    {
    	tl.setFrameProperty("tweenType", 'none');
    	dom.removeDataFromDocument(tweenAdded);
    }
    else
    {
    	tl.createMotionTween();
    	dom.addDataToDocument(tweenAdded, "integer", 1);
    }

     

    I hope it helps.

     

    Regards,

    JC

    JoãoCésar17023019
    Community Expert
    Community Expert
    April 20, 2023

    Even better, you can check the value of the frame.tweenType property.

    Firewood:D
    Inspiring
    April 20, 2023

    Great! Simply amazing! I tried several commands and it worked fine,
    Forgive me for another unreasonable request. If there is an empty layer or a blank keyframe in the frame selected by the mouse, can it be automatically skipped instead of adding tweening to all of them, which will happen in character animation There are many layers, and it can be very uncomfortable to have an empty layer with no objects and also tween it.
    I don't know much about these, so I don't know the difficulty of his implementation, sorry!

    Firewood:D
    Inspiring
    April 20, 2023

    .