-
Script only works properly if i re-run it each time – need help
Hi, i am trying to create a small script for my own workflow.
The part of the script i need help with is where i have a button that creates a new layer above the layer i have selected.
The problem is that the script only works properly once, after the first time it has been run either from extendscript or from the window tab within after effects – meaning, that the layer that was selected before running the script, gets the new layer created above it, which is right, but when i then select another layer and click the button, it still creates it above the original layer that was selected before the script was initiated. in order for it to work on another layer, i need to select the new layer and then re-run the script.
TLDR – Is there something specific that needs to be done in order for the button to keep creating above the new layer that i select each time without having to re run the script?
the code is as basic as it comes:
var myLayers = app.project.activeItem.selectedLayers; var firstLayer = myLayers[0]; var secondLayer = myLayers[1]; moveButton.onClick = function() { secondLayer.moveBefore(firstLayer); } createButton.onClick = function() { var newSolid = myComp.layers.addSolid([0.8, 0.2, 0.5], "NEW LAYER", 1920, 1080, 1).moveBefore(firstLayer); }