Expand my Community achievements bar.

Moving Objects Around the Form

Avatar

Former Community Member

I found this great sample on how to move objects on the form, allowing a user to move objects (in this case buttons) around the form.

http://cookbooks.adobe.com/index.cfm?event=showdetails&postId=16519

This solution is based on the "fly swatter" example by Thom Parker (http://www.pdfscripting.com) and samples by John Brinkman (http://blogs.adobe.com/formfeed/) looking at x, y, w and h properties.

The code is on exit of buttons...MY QUESTION IS...Is possible to move a static object (e.g. circle) at the same time you are moving the button.

Thank you.

var

gridX = xfa.layout.x(gridPICK);

var

gridY = xfa.layout.y(gridPICK);

var

gridW = xfa.layout.w(gridPICK);

var

gridH = xfa.layout.h(gridPICK);

var

markerDim = xfa.layout.w(mrk) / 2;

//console.println("x: " + gridX + ", " + "y: " + gridY + ", " + "w: " + gridW + ", " + "h: " + gridH + ", " + "marker: " + markerDim);

var

mouseX = event.target.mouseX;

var

newX = (mouseX + "points").toString();

var

mouseY = 595.276 - event.target.mouseY;

var

newY = (mouseY + "points").toString();

if

(mouseX <= gridX + markerDim)

{

this.x

= (gridX + markerDim + "points").toString();

this.x

= (gridX + markerVim + "points").toString();

}

else

if (mouseX >= gridX + gridW - markerDim)

{

this.x

= (gridX + gridW - markerDim + "points").toString();

this.x

= (gridX + gridW - markerVim + "points").toString();

}

else

{

this.x

= newX;

}

if

(mouseY >= gridY + gridH - markerDim)

{

this.y

= (gridY + gridH - markerDim + "points").toString();

this.y

= (gridY + gridH - markerVim + "points").toString();

}

else

if (mouseY <= gridY + markerDim)

{

this.y

= (gridY + markerDim + "points").toString();

this.y

= (gridY + markerVim + "points").toString();

}

else

{

this.y

= newY;

}

//console.println("x: " + newX + " y: " + newY);

 

this.border.edge.color.value

= this.border.fill.color.value;

6 Replies

Avatar

Level 10

Hi,

The slightly updated version of that example is available here: http://assure.ly/hXsh10.

The solution works because the button has events that we can script against. In this case the script in the exit event of the buttons. (Note that the script in the mouseDown event is just cosmetic, to colour the border/highlight the "active" button).

The trouble with static objects is that they do not have events that you can script against. You can change the position of a circle (just like the button), but you would need a second object to control it.

Maybe a button next to the circle, captioned "move this circle". Once the mouse is clicked elsewhere, the script would move the associated circle to the mouse position.

Does that make sense?

Niall

Avatar

Former Community Member

Thank you Niall,

That would work...I accutualy need to move a circle...a button next to the circle, captioned "move this circle" would work. Once the mouse is clicked elsewhere, the script would move the associated circle to the mouse position. As long as the circle is moved to mouse position. Can you perhaps provide a sample code that will acomplish it ?

Thank you!

Avatar

Level 10

@ Niall,

tI think your slider sample may be the right thing for this request.

I actually can't find it, do you have it handy?

Avatar

Level 10

Hi,

The sample code is on the form. All you would need to change are the last bits that move the object.

In the example, we use "this" which refers to the buttons that contains the script.

In your case you would need to change "this" to the name of the associated circle, let's say "circle1".

// script above this stays the same

if (mouseX <= gridX + markerDim)

{

     circle1.x = (gridX + markerDim + "points").toString();

}

else if (mouseX >= gridX + gridW - markerDim)

{

     circle1.x = (gridX + gridW - markerDim + "points").toString(); 

}

else

{

     circle1.x = newX;

}


if (mouseY >= gridY + gridH - markerDim)

{

     circle1.y = (gridY + gridH - markerDim + "points").toString(); 

}

else if (mouseY <= gridY + markerDim)

{

     circle1.y = (gridY + markerDim + "points").toString();

}

else

{

     circle1.y = newY;

Does that helps?

Niall

Avatar

Level 10

Thanks Radzmar!

We also use the moving objects in a form that demonstrated the difference between flowed and positioned subforms: http://assure.ly/eSGQMt.

The same principles apply.

Niall

Avatar

Former Community Member

It works! Thank you so much. That is perfect!