• home
  • forum
  • my
  • kt
  • download
  • Bezier Curve

    Author: 2008-09-25 15:59:15 From:

    In this tutorial you will learn how to make a curve using flash API and draw with a mouse movement.
    Free Flash Tutorials, Actionscript, Bezier Curve

    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);
    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:
    holder.clear();
    Now you will have a single curved line following the mouse.

    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(); }

    This is the result, using one line and a clear button:
    Free Flash Tutorials, Actionscript, Bezier Curve

    Code Explanation

    _root.createEmptyMovieClip("holder", 33);
    Create new Movie Clip for our drawing.

    this.onMouseMove = function() {
    This code runs every time the user moves the mouse.

    holder.lineStyle(2, 0x009933, 10);
    Set the color of the line with the lineStyle() function from the drawing API.

    holder.moveTo(100, 200);
    Start the drawing at the (100,200) coordinate.

    holder.curveTo(_xmouse, _ymouse, 400, 200); }
    Draw a curve that follow the mouse coordinate and ends at (400,200).

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      3D (20)
      Math Physics (14)
      3rd Party (5)
      Navigation (60)
      Actionscripting (26)
      Optimization (16)
      Animation (32)
      Projector (9)
      Audio (46)
      Special Effects (112)
      Backend (25)
      Text Effects (65)
      Drawing (18)
      Tips and Techniques (41)
      Dynamic Content (25)
      Tricks (6)
      Games (66)
      Utilities (19)
      Getting Started (71)
      Video (10)
      Interactivity (27)
      Web Design (29)

    New

    Hot