Walled Bouncing Line Animation Using Flash And Action Script
Do you want to create an animation of bouncing line using Flash and Action Script. In this animation, a line will keep bouncing after an edge hit a wall. The area is a rectangle so that the line will keep bouncing inside the rectangle. What we need to produce the animation is just a script (no movie clip at all).
Preview
Source Code
[as3]//By : Isusx’s Programming Corner
//URL : http://isusx.com/
//The edge speed
//The first Array(4,4) is the x and y speed for the first line edge
//The second Array(4,4) is the x and y speed for the second line edge
v = Array(Array(4, 4),Array(4, 4));
//The line initial position
//Array(2*Stage.width/3, 0) is the initial coordinate of the first line edge
//Array(0, Stage.height/3) is the initial coordinate of the second line edge
l = Array(Array(2*Stage.width/3, 0), Array(0, Stage.height/3));
this.onEnterFrame = function(){
//Coordinate calculation and speed determination
for(i=0;i<2;i++){
l[i][0] += v[i][0];
l[i][1] += v[i][1];
if(l[i][0] < 0 || l[i][0] > Stage.width)
v[i][0] = -v[i][0];
if(l[i][1] < 0 || l[i][1] > Stage.height)
v[i][1] = -v[i][1];
}
//Drawing line
this.clear();
this.lineStyle(1,0,100);
this.moveTo(l[0][0], l[0][1]);
this.lineTo(l[1][0], l[1][1]);
}
[/as3]
Download
Click here to download the source code
Copyright Note
This script is free to use and can be modified as you wish.
Related Links
Flash Documentation, Guide and Complete Reference




