Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making my lines form a box with actionscript 1

Status
Not open for further replies.

TaiChi56

Technical User
Mar 6, 2002
188
0
0
US
I have four lines that sit on the stage forming a cross. When the user clicks on a link the lines move and form a box. It happens quickly. I want the lines to form a box moving at a slower rate. Here is my code for the lines that form the box. How can i adapt actionscript to tell it to go slower when forming?

on (release){
_root.upperline._y=56.3
_root.lowerline._y=374.9
_root.rightline._x=500.5
_root.leftline._x=31.3
}

Thank you. The secret in education lies in respecting the student. {Ralph Waldo Emerson}.
 
Tween the lines in place. Regards,

oldman3.gif


Don't worry, if my reply is wrong, BillWatson will clean it up for me!
 
Thank you I know I can do that but i would much rather do it with actionscripting. It looks better than doing it by tweening. Any suggestions. The secret in education lies in respecting the student. {Ralph Waldo Emerson}.
 
not a full answer but to give you an idea of how it can be done

First Frame:

a= a number
b= a number

yourlines x position = a
yourlines y position = b



Second frame:

contains an " if " statement which says if lets say " b" gets to its target then stop or do something else

Third Frame:

increase your values by a small amount like

a=a+1 for example
b=b+1
back to frame 2
etc
 
It really depends on how the lines move to form the box, and if the cross and box are 2D or 3D. If the cross and box are 2D and the horizontal line of the cross splits into two lines, then you could make each line a MC, and slowly progress the lines to their final destination. You would also do this with the vertical lines. But if you were dealing with 3D, or really, the impression of 3D, you would be dealing with lines that possibly rotated while moving--that complicates things. I would consider a simple 2D, or putting the pen to paper on the 3D version, because it would be more complicated than a post on this site.
 
Try this, there's an example here:


4 lines on stage - each one a movieclip (named line 1 thru line 4) and two buttons instance names btnCross and btnBox - here's the code:

//positions for cross
Code:
 initX = [150, 250, 250, 250];
initY = [200, 200, 100, 200];

//positions for box
Code:
finalX = [200, 200, 200, 300];
finalY = [150, 250, 150, 150];

//move from one to the other
Code:
function moveLines(x, y) {
	var speed = 10;
	this.onEnterFrame = function() {
		for (var i = 0; i<4; i++) {
			var xDiff = (x[i]-this['line'+(i+1)]._x)/speed;
			var yDiff = (y[i]-this['line'+(i+1)]._y)/speed;
			this['line'+(i+1)]._x += xDiff;
			this['line'+(i+1)]._y += yDiff;
			if (Math.abs(xDiff)+Math.abs(yDiff)<.01) {
				this.onEnterFrame = null;
			}
		}
	};
}
//button triggers
Code:
btnBox.onRelease = function() {
	moveLines(finalX, finalY);
};

btnCross.onRelease = function() {
	moveLines(initX, initY);
};

stop();
 
It's the old age, reflexes aren't waht they were...
 
Excellent Wangbar, ust want I was looking for. Thanks. The secret in education lies in respecting the student. {Ralph Waldo Emerson}.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top