Updating (redrawing) Components from JSFL
I am building a Flash Panel for a Custom Component I have built. I didn’t want to use the CustomUI setting for components because I wanted to be able to allow this panel to edit multiple instances of this component at once. The problem I have run into is figuring out how to get my component instances on the stage to update or redraw themselves when a property changes.
I searched and searched for a way to do this and didn’t find anything that worked. The problem lies in the fact that the Flash Panel doesn’t (and shouldn’t in my opinion) know about the specific instances on the stage. JSFL does know about those instances but only as it’s predefined Element object type, so there is no way to access public functions of that component from JSFL. You can access the Inspectable properties of the component, but changing these values does not tell Flash’s live preview to redraw the components.
So, if you were able to follow all of that, the problem here is that I can update properties of my components using my Flash Panel and JSFL, but there is no way to force redraw those components on the stage when I change the properties… until now.
I found that when deselecting my components that I had just changed properties on, the stage would redraw them. So all I did in JSFL was deselect the components and reselect them. Thankfully this forces a redraw of the live preview components. Here’s what that JSFL code looks like:
function invalidateStage() {
var selectedArray = fl.getDocumentDOM().selection;
fl.getDocumentDOM().selectNone();
fl.getDocumentDOM().selection = selectedArray;
}
Now when I call invalidateStage in my JSFL after I have changed a property on my component, the stage will effortlessly update before my eyes.