Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

69 users online



Creating & moving a line using actionscripting?

Creating & moving a line using actionscripting?

Currently viewing this thread: 1 (0 members and 1 guests)


knappster

knappster

Flash designer, learner.
Status: Offline!

Creating & moving a line using actionscripting?

I've went through forum posts and found a few threads on creating a line. What I'd like to do is create a line (a curve, not a straight line) and control both points of the line using actionscript tweening. I haven't found very much on this here in forums. Would anyone happen to know a good site that would have something of this subject i'd be able to read up on? Or just give me a few pointers or lines of code to point me in the right direction?

I'm actually trying to make a sorta stick-man walking, but I wan't it to look a little more man than stick.

Thanks,

aok

hamstu

hamstu

Neverside Newbie
Status: Offline!

You can use code like this to draw a curved line, with the Flash Drawing API.

Code:

// Create the MC
var cv:MovieClip = _root.createEmptyMovieClip("cv", 1);
// Set the linestyle
cv.lineStyle(2, 0x000000, 100);
// Position our virtual 'cursor'
cv.moveTo(20, 20);
// Draw a curve, curveTo(controlpointX, controlpointY, pointx, pointY)
cv.curveTo(100, 500, 200, 200);

As for animating it, you'd have to have an some sort of onEnterFrame loop constantly redrawing your line..something like this maybe...

Code:

// Create the MC
var cv:MovieClip = _root.createEmptyMovieClip("cv", 1);
// Setup Some Vars
var x:Number = 200;
var y:Number = 500;
// Create a function to draw our curve
function drawCurve(ctrlX:Number, ctrlY:Number):Void {
// Set the linestyle
cv.lineStyle(2, 0x000000, 100);
// Position our virtual 'cursor'
cv.moveTo(20, 20);
// Draw a curve, curveTo(controlpointX, controlpointY, pointx, pointY)
cv.curveTo(ctrlX, ctrlY, 200, 200);
}
cv.onEnterFrame = function() {
// Comment out the following line, and the line won't dissapear when anohter is drawn.
cv.clear();
_root.drawCurve(_root.x++, _root.y++);
};

To tell you the truth, it wouldn't be very easy >_<

Maybe you should just animate it the good ol' way Tongue

___________________

http://www.hamstu.com/images/hamstu_com.gif

Last edited by hamstu, June 16th, 2005 12:14 AM (Edited 2 times)

Smurf2002

Smurf2002

Vivo para el sanwich!
Status: Offline!

Doing an actual animation in AS would be extremely hard and take a hundered times longer than if you were to animate it by hand.

___________________

I have flash in the pants!

Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0071 seconds.