Skip to main content
Firewood:D
Inspiring
August 10, 2023
Answered

How does jsfl use the position coordinates of the object?

  • August 10, 2023
  • 1 reply
  • 1532 views

Click on an element, and the coordinates of the object will be left in the record panel, for example

an.getDocumentDOM().mouseClick({x:951, y:371.7}, false, true);

Now, the XY coordinate value is fixed, can the element position be dynamically obtained for subsequent calls?
For example, I clicked on the A element in the first step, and after the second step, I want to use JSFL to select A instead of clicking A again with the mouse.
The position of the element can be in various places. I hope the value of this xy is not fixed.
I don't know if my idea is whimsical, I can only describe what I want to achieve as much as possible,
Thank you very much if you can!

This topic has been closed for replies.
Correct answer Vladin M. Mitov

You need to set a keyframe first and then give the loop attribute. The normal operation is to select all three symbols after setting a keyframe, but I only need to select symbol 1, and only control symbol 1 after setting a keyframe, instead of selecting it after setting a keyframe. Three symbols control.
This is possible when auto keyframing is activated


"...but I only need to select symbol 1, and only control symbol 1 after setting a keyframe..."


Alright, what's stopping you from doing it?
You just need to find a way to distinguish "symbol 1" - either by libraryItem, by name, or by index within the layer itself. Once you know the element of the "symbol 1", you can deselect all, select the proper element and set the properties you want.

	var mySymbolName = "yellow triangle" // Example
	var doc = fl.getDocumentDOM();
	var tml = doc.getTimeline();
	var myLayer = tml.layers[ tml.currentLayer ];
	var myElement = getElementByName( myLayer.frames[ tml.currentFrame ], mySymbolName );
	
	if( myElement ){
		doc.selectNone();
		myElement.selected = true;
		myElement.loop = "single frame";
		myElement.firstFrame = 0; // Or something else
	}
	
	function getElementByName( frameObj, symbolName ){
		for( var i = 0; i < frameObj.elements.length; i++ ){
			if( ! frameObj.elements[i].libraryItem ) continue;
			if( frameObj.elements[i].libraryItem.name.split("/").pop() === symbolName ){
				return frameObj.elements[i];
			}
		}
		return null;
	}

 

Just save this code as a command, assign it a keyboard shortcut and keep executing the command each time after setting a new keyframe.


 

1 reply

Vladin M. Mitov
Inspiring
August 11, 2023

1. You can select an unknown element at specific position , simulating mouse clicks:

 

an.getDocumentDOM().mouseClick({x:951, y:371.7}, false, true);

 

 

2. Or you can select the elements you want, overriding the array, called document.selection.

 

var document = fl.getDocumentDOM();
var el = document.getTimeline().layers[0].frames[0].elements[0];
document.selection = [el];

 

 

3. Or you can use the individual selection property of a given symbol instance:

 

var document = fl.getDocumentDOM();
var el = document.getTimeline().layers[0].frames[0].elements[0];
el.selected = true;

 

 

 

- Vlad: UX and graphic design, Flash user since 1998Member of Flanimate Power Tools team - extensions for character animation
Firewood:D
Inspiring
August 12, 2023

Following the instructions you gave me, I continued to ponder for a while, and found that I seemed to have gone astray. Let me demonstrate my purpose.

 A layer has three symbols (or more) on the same layer. When using the automatic keyframe button, you can select one of the symbols, directly type a keyframe and control the editing symbols, and the symbols do not affect each other.

What I want to achieve is the code to simulate the restoration operation, and its logic is
1. Select the symbol and record the location,
2. Mark the key frame
3. Select the previous symbol again,
The automatic recording of the position of the symbol is the key information, and the position of the symbol can be anywhere in the scene.

Multoman
Inspiring
August 15, 2023

I've reread your explanation several times, but I still don't understand your idea. Write in more detail what you want to do