First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Vernon Morris | Website:
This tutorial assumes you are comfortable creating movie clip symbols and giving them instance names as well as writing basic functions in ActionScript.
  • Step 1: Create a new Flash document and add two movie clips. In the property inspector, name them 'point1' and 'point2' (any names will suffice but my example will use these particular names)
  • Step 2: Let's start writing a function that draws a line from 1 side of the screen through these two points (wherever it is that they may be) and to the other end of the stage.
  • Step 3: Lets right the beginning of our function:

  • function perfectLine(myClip1, myClip2 ,suppliedDepth ){
    //_slope: First let's find the slope of a line between the two clips
    _slope = -(myClip1._y - myClip2._y)/(myClip1._x - myClip2._x);

    //These variables represent the total left, right, top and bottom
    //of the screen to which we will draw a line. We will use the slope that
    //we just found to calculate these variables later on

    var _totalLeft:Number;
    var _totalRight:Number;
    var endY:Number;
    var staRtY:Number,
    var newDeltX:Number;
    // Next is where the movieClip in wich we will house our line.
    //Remember that we need a MovieClip to draw a line
    // (though in Flash 9 it will no longer be necessary to draw in a mc)

    var drawLineInThisClip:MovieClip;

    //The _stringCount is a just a variable that we will append to each line's movieclip
    // Each line needs to be associated with a movieclip. Each clip, of course,
    // requires its own, distinct depth-- we might after all want multiple lines.
    // on the Stage and we can now assign them different depths

    var _stringCount = suppliedDepth;

    //The next 3 variables let you customize the following properties of our
    //humbly named 'perfect lines'
    //They're pretty self-explanatory

    var lineThickNess = 3; // How thick the line is
    var lineRGB = 0x000033; //the color of the line
    var lineAlpa = 90; //The Alpha of the line

    //_totalRight, not surprisingly, represents how far on the right we want to be able to draw
    // Since we want to be able to draw ALL the way to the right we use 'Stage.width'
    //_totalLeft is the x position on the left which is zero. Remember in Flash's
    //coordinate system x values start at zero on the absolute left.

    _totalRight = Stage.width;
    _totalLeft = 0;

    //Here is where we create the movieClip that will house our line.
    drawLineInThisClip =_root.createEmptyMovieClip(('line'+_stringCount), suppliedDepth)

» Level Intermediate

Added: 2007-01-21
Rating: 10 Votes: 3
(10 being the highest)
» Author
Webmaster at Visit site to see this line in various Flash based programs.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.