Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Moving elements with JSFL not being saved properly

Participant ,
Feb 23, 2018 Feb 23, 2018

For our application, we want our symbols to be centered. Our symbols contain only shapes. A symbol can have multiple layers as long as it is comprised of shapes.

I wrote a script to center the symbols, since more often than not, some artists would forget about this rule. We've been doing some initial testing and in general it works. However we came across an aberration.

The script "corrects" the file. The double quotes are there because I can inspect and see the item is in the location I want. However when I save, close, and then re-open, the file is back in it's original position.

This could totally be user error. The script to do this is here.

function recenterSymbols(lib) {

  var fixed = 0

  var items = lib.items.slice()

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

  var item = items

  if (item.itemType == 'movie clip') {

  var timeline = item.timeline

  var layers = timeline.layers

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

  var layer = layers

  for (var f=0;f<layer.frames.length;++f) {

  var frame = layer.frames

  for (var e=0;e<frame.elements.length;++e) {

  var elem = frame.elements

  var w = elem.width

  var h = elem.height

  elem.x = -w/2.0

  elem.y = -h/2.0

  }

  }

  }

  }

  }

}

var dom = fl.getDocumentDOM()

var lib = dom.library

fl.outputPanel.clear()

recenterSymbols(lib)

Note this is an isolated test case and doesn't work 100%, but was good enough for me to isolate things. My actual code computes the bounds of all the layers and then from there computes the offset. This code is for simplicity of getting the idea across.

One other curious, thing, and perhaps I don't understand things correctly. I am assuming element.x and element.y, which are the registration points also correlate to the x and y value in the Properties panel? The reason I'm asking is because I would expect the code above to center the element. However what I end up seeing is that the shape ends up having it's lower right corner at the cross hair (registration point).

This image shows what I am seeing (this is by running this script)

element resize issue.png

I also ran into this.

JSFL reg point move does not save correctly

It's. from a few years ago, but I wonder if it is indicative that this is a bug.

747
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2018 Feb 24, 2018

your jsfl works as expected for me after a save and reopen.

save with a new name and then double check that you're opening the correct (newly named) file.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 24, 2018 Feb 24, 2018

Hmmm, what's the best way to post a file? I wonder if it is endemic to this particular file. And just curious, what is the version you are using? I'm using the latest (2018, Build 107) on the Mac.

I've tried same name, new name. The results are the same

Oh, one other question, how many symbols were in the file you tested out?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2018 Feb 24, 2018

Screenshot - 2_24_2018 , 7_51_08 AM.png

tested on windows with one symbol.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 24, 2018 Feb 24, 2018

Interesting. I wonder if it is an issue only related to the Mac. I also re-did the test. I tried:

-Just saving, closing the document, and re-opening

-Saving as new name, closing the document, and opening the new file

Also permutations of quitting the app as well as opening the file from the desktop (the files are on my desktop), from the File:Open menu and from the Open Recent Item panel that shows up in the main window when no files are opened. All yield the same results.

Just curious, why did you ask about saving as a new name versus just saving the file?

I did actually find a work around. Upon analyzing things, it seems that the problem exists on the last symbol processed. So my original test file had only 1 symbol. When I added more, the last symbol processed did not have the values persist. This makes me wonder is they have some form of caching system in place. I've noticed that Animate seems to hold changes, but doesn't actually apply them until some trigger point. For example, you can update the Accessibility description and if you don't do it right, the changes don't stick.

I found a work around, which is terrible. And for some reason it needs all of this. If you remove any part, it may work or it may not.

function recenterSymbols(dom, lib) {

  var fixed = 0

  var items = lib.items.slice()

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

  var item = items

  if (item.itemType == 'movie clip') {

  lib.editItem(item.name)

  var timeline = item.timeline

  var layers = timeline.layers

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

  var layer = layers

  for (var f=0;f<layer.frames.length;++f) {

  var frame = layer.frames

  for (var e=0;e<frame.elements.length;++e) {

  var elem = item.timeline.layers.frames.elements

  var w = elem.width

  var h = elem.height

  var sel = [elem]

  dom.selection = sel

  elem.x = -w / 2.0

  elem.y = -h / 2.0

  dom.selectNone()

  }

  }

  }

  lib.editItem(item.name)

  }

  }

}

var dom = fl.getDocumentDOM()

var lib = dom.library

fl.outputPanel.clear()

recenterSymbols(dom, lib)

I'd be happy to find out that I'm doing something dumb.

One question I have is it does seem that the library.editItem is important. Is there any means of "unediting" an item? Only asking because when the script is done, the last symbol is highlighted and I prefer to have it in a state where things cannot be accidentally changed due to an errant key or mouse event

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 24, 2018 Feb 24, 2018
LATEST

"Just curious, why did you ask about saving as a new name versus just saving the file?"

to make sure you weren't saving to another directory and then opening the old file from the original directory.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines