First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Vernon Morris | Website: http://www.mathwarehouse.com/
' Line Tutorial Page Three
In the next part, our function will look at the magnitude of our slope. If the slope is vertically oreinted or has an absolute value greater than 1, then we will draw our line 1 way, and if the line ihorizontally oriented a different way. It took me a while to realize why my lines where sometimes blurring, but it was becuase I was drawing them to several thousound pixels beyond the Stage's height, and apparently that is too much for Flash to do without some distortion.
// the next block is how we will draw the line
// if the absolute value of the slope is greater than 1
else if( (Math.abs( _slope ) > 1) && (_slope != 0) )
{
// the next few variables will be soon be used
// when we draw our line
var newDeltY:Number;
var newDeltY2:Number;
var _newX:Number;
var _bttmX:Number;
// Since Flash coutns the top of the stage as y =0
// newDeltY = the y value of our clip
newDeltY = myClip1._y;
// Now use our slope and the prior variable to find
//the x to which we want to draw our line
_newX = myClip1._x + (newDeltY/ _slope);
newDeltY2 = Stage.height- myClip1._y;
_bttmX = myClip1._x - (newDeltY2 / _slope);
// Now move pen of line to _btttmX and Stage.height
//the latter point is the bottom most point of our line
drawLineInThisClip.moveTo( _bttmX , Stage.height);
// Drw line to _newX and the top of the stage ('0')
drawLineInThisClip.lineTo(_newX,0);
}
// the final block is how we will draw the line
// if the absolute value of the slope is LESS than 1
else
{
//deltaX is from point to total right (Stage.width)
newDeltX = (Stage.width - myClip1._x);
// endY is the y value corresponding with
//newDeltX on a line with our _slope

endY = ( myClip1._y - ( newDeltX*_slope ));
staRtY = ( myClip1._y )+ (myClip1._x*_slope );
//_totalLeft is at the very top of the function and we initialized it to 0
//because we want to start at the total left of the Stage or x =0
//_totalRight we initialized to Stage.width which is the total right of the stage
// both variables are at the very top of the funtion

drawLineInThisClip.moveTo(_totalLeft, staRtY);
drawLineInThisClip.lineTo(_totalRight,endY);
}
} }//end of draw line function

The last step:
_root.onEnterFrame = function(){ perfectLine(_root.point1, _root.point2, 33, 'myline'); };
» Level Intermediate

Added: 2007-01-21
Rating: 10 Votes: 3
(10 being the highest)
» Author
Webmaster at www.mathwarehouse.com. 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!

Comments

  • 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: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.