This is out of an AS 3 script that I use to bounce several balls off of the stage boundaries. Should illustrate the idea enough to be converted to AS 2.0 (see bold code).
package doc
{
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.display.Stage;
import flash.filters.*;
public class MovingCircle extends Sprite
{
private var tmr : Timer private var xDir : int = 1;
private var yDir : int = 1;
private var colur:uint;
public function MovingCircle (colr : uint, radius : Number)
{
colur = colr;
graphics.beginFill (colr, 1);
graphics.drawCircle (0, 0, radius);
graphics.endFill ();
tmr = new Timer (30);
tmr.addEventListener ("timer", drift);
tmr.addEventListener ("timer", glow);
tmr.start ();
} private function drift (event : TimerEvent)
{
if (x < this.width/2)
{
x = this.width/2;
xDir *= - 1;
} else if (x > (parent.stage.stageWidth-(this.width/2)))
{
x = parent.stage.stageWidth-(this.width/2);
xDir *= - 1;
}
if (y < this.height/2)
{
y = this.height/2;
yDir *= - 1
} else if (y > parent.stage.stageHeight-(this.height/2))
{
y = parent.stage.stageHeight-(this.height/2);
yDir *= - 1;
}
x += xDir;
y += yDir;
}
private function glow(event:TimerEvent){
var gf:GlowFilter = new GlowFilter(colur, Math.random(), Math.random()*10, Math.random()*10, Math.random()*10, BitmapFilterQuality.HIGH, false, false)
this.filters = [gf];
}
}
}
The collision code works as does the circle movement code but the dont seem to work together. If i just place the circle over the line with out the movment code it detects the collision
I have it moving see the fla at in the first post, but it does not detect the collision, could you take a look. I want it to detect the collsion using math and bounce it back off the wall.
Well the original one I downloaded did not have any code on the ball itself. The code i posted was a modified version of what I downloaded from the first post and the collision detection worked after I used the code I posted.
Sorry, that was my fault changed it after you saw it.
Take alook at the attatched, the collision works but the rection does not work that well, is there a way to make the object bouce more off the wall, i think its not working as it did becase of the addition of user controled movement.
Any one able to suggest a resolution? The attached collision detection/reaction works but when you add controls to move the circle with the arrows then the collision reaction stops working