pradeepkumar
pradeepkumar

Reputation: 3

Changing Shape Dynamically Using Mouse In As3

I want to dynamically change the shape of a shape in as3. Say for example, on clicking and dragging on shape square the shape should change according to my mouse movement, direction. I have pasted a link below which display my requirement, selecting one shape and edit edges option, then click the shape and drag, the shape will change according to mouse movent and direction based on some math calculation. Is that possible in AS3.

http://www.shodor.org/interactivate/activities/Tessellate/

Upvotes: 0

Views: 108

Answers (1)

Creative Magic
Creative Magic

Reputation: 3141

Yes, it is possible to make this type of programs.

I suggest you looking into Sprite's graphics object. It has the API to draw primitives, lines and curves.

The reason why you should use Sprites in this case is because it extends InteractiveObject => they support user input, like mouse or touch inputs.

Here's an example of creating triangle:

var s:Sprite = new Sprite();
s.graphics.lineStyle(1, 0x000000); // optional
s.graphics.beginFill(0xff0000); // optional
s.graphics.lineTo(0, 100);
s.graphics.lineTo(100, 100);
s.graphics.lineTo(0, 0);
s.graphics.endFill();
addChild(s);

You can combine mouse events to track input and event ( enter frame in particular ) to redraw your shape depending on the mouse position.

To redraw the shape, you might want to call graphics.clear() method on that object to erase it from the screen.

Upvotes: 1

Related Questions