Skip to main content
Robin Müller
Participating Frequently
February 6, 2023
Question

problem with .rect - problem with move

  • February 6, 2023
  • 1 reply
  • 597 views

Hello,
I can't move the x1 coordinate of the text2 field - the field won't change. The console does not display anything. Thanks for the advice

// getField("text1").rect = [0, 500, 200, 450] — field already exist
// getField("text2").rect = [0, 450, 200, 400] — field already exist

// 1. case — DOESN'T WORKS
var text1 = getField("text1").rect;
getField("text2").rect[0] = text1[0]+100;
// END of 1. case

// OR

//2. case - DOESN'T WORKS
getField("text2").rect = [ text1[0]+100, text1[0], text1[0], text1[0] ]; // 2. CASE — DOESN'T WORK
// END of 2. case
This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
February 6, 2023

#1 doesn't work because you can't edit a single item in the array. You have to edit it and then re-apply it as a whole back to the rect property.

#2 doesn't work because because you're applying the same (wrong) value to items 1-3 in the array, which means the height of the field will be zero. Also, value 2 must be larger than value 0, and it's not in your case.

 

Try this:

 

var text1Rect = getField("text1").rect;
text1Rect[0] += 100; // move the field 100 points to the right
text1Rect[2] += 100;
getField("text2").rect = text1Rect;

 

Robin Müller
Participating Frequently
February 6, 2023

my second example was a typo. Thanks for the explanation