Skip to main content
Inspiring
July 1, 2011
Question

copy a shape

  • July 1, 2011
  • 1 reply
  • 619 views

Hi ,

I am working in a complicated shape manuplation project.

In that user can join 2 shapes , he can duplicate, he can delete a particular part of a shape ect;

In the following code copies a shape and adds to stage.

import flash.display.Shape;

var sh1:Shape = new Shape();

sh1.graphics.lineStyle(2,0x000000);
sh1.graphics.drawRect(45,45,100,100);
addChild(sh1);
trace(sh1.x);
trace(sh1.y);
sh1.rotation = 45;


trace(sh1.x);
trace(sh1.y);

var sh2:Shape = new Shape();
sh2.graphics.copyFrom(sh1.graphics);
addChild(sh2);
sh2.x = 200;

In this all the properties of sh1 copied except the rotation value.

But i dont want to assign it directly like sh2.rotation = sh1.rotation;

Is there any other way to do that?

Thanks,

Shanthi

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
July 1, 2011

how do you want to assign the rotation of sh2?


Inspiring
July 2, 2011

Is this possible to find the x y points after rotation.

Before rotaion x, y points may be 0,0;

after rotation the points become -10. -14;

So If I draw a shape using that point it will draw a shape with the position rotated.

But If I trace x y positions after and before rotation it shows 0, 0 only.

This is the problem I am facing.

In my app user can drag and drop a shape into another.

If he drops the two shapes become one.

Suppose shape 1 rotated 45% then id i add another shape into that the added shape also rotates 45%.

But I want to avoid that.

kglad
Community Expert
Community Expert
July 2, 2011

what do you mean by, "..the two shapes becomse one."?

if you mean you're reparenting the dropped shape so its parent is the dropTarget, rotate the dropped shape by -dropTarget.rotation to make it apear unrotated.