flashjsfl

JSFL get current screen view position


When authoring in Flash, how do I obtain the current coordinates of the screen artboard viewport when using JSFL?

As in here, I'd expect the top left to be a little less than x:350 and y:200.

flash artboard

When running JSFL scripts, I want the script to use the current zoom / pan position of the user's view, and not absolute positioning from the stage.

In other words, I understand how to position such as:

var dom = fl.getDocumentDOM();
dom.library.addItemToDocument({x:100, y:100}, "symbolType");

Instead, I want to reference the user's current screen position.

meta code:

dom.library.addItemToDocument({x:fl.screenX, y:fl.screenY}, "symbolType");

Solution

  • One way to do it would be to use Document.clipCopy() and Document.clipPaste(). It should paste in the center of the current viewport. You can then grab the location from the newly pasted element (which will now be the only selected item) and then delete it if you want. You could use Document.zoomFactor and Document.viewMatrix to figure out a screen position other than center.