Subscribe to our newsletter:
Page 1
DOWNLOAD SOURCE FILE FOR THIS TUTORIAL
In this tutorial you will learn how to make a curve using flash API and draw with a mouse movement.
Create a new document and in the actions for the first frame paste:This function is used to draw a curve, anchorX and anchorY are the position of the end of the curve. And controlX and controlY tell to which direction the curve is going to be draw.
If you test the code now you will notice that the framerate will go down after a while, that's because it's drawing to many lines.
Add this code before the rest:Now you will have a single curved line following the mouse.
You can also use a button to erase the drawing:This is the result, using one line and a clear button:
Create new Movie Clip for our drawing.This code runs every time the user moves the mouse.Set the color of the line with the lineStyle() function from the drawing API.Start the drawing at the (100,200) coordinate.Draw a curve that follow the mouse coordinate and ends at (400,200).
In this tutorial you will learn how to make a curve using flash API and draw with a mouse movement.
Create a new document and in the actions for the first frame paste:
//empty Movie Clip to hold the drawing
_root.createEmptyMovieClip("holder", 33);
//event triggered when the mouse moves
this.onMouseMove = function()
{
//how the line looks (thickness, color, alpha)
holder.lineStyle(2, 0x009933, 10);
//move to the start of the curve
holder.moveTo(100, 200);
//explained below
holder.curveTo(_xmouse, _ymouse, 400, 200);
}
curveTo(controlX, controlY, anchorX, anchorY);If you test the code now you will notice that the framerate will go down after a while, that's because it's drawing to many lines.
Add this code before the rest:
holder.clear();You can also use a button to erase the drawing:
//clear is the button instance
clear.onRelease = function()
{
//call the clear function
_root.holder.clear();
}
Code Explanation
_root.createEmptyMovieClip("holder", 33);
this.onMouseMove = function()
{holder.lineStyle(2, 0x009933, 10);holder.moveTo(100, 200);holder.curveTo(_xmouse, _ymouse, 400, 200);
}




help
and feedback
latest
news
latest
forum entries