Sorry, worked it out.
Thanks for anyone who read the thread before.
EDIT: The problem was that I had a general Ball class with functions for velocity and acceleration. However, I had forgotten to define an initial acceleration and velocity value in the class. So, vx was undefined, but it was trying to add this value to the x value of the Ball on every frame. I’m unsure why, but this resulted in the x (and y) values defaulting to -107374182.4, and the Ball disappearing from stage.
So if you’re making a class like that, be sure to define the velocity and the acceleration at the start
Ball.as:
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Ball extends Sprite
{
public var vx:Number;
public var vy:Number;
public var ay:Number;
public var ax:Number;
private var _color:uint;
public var radius:Number;
public function Ball(color:uint = 0xFFFFFF00, radius:Number = 40):void
{
this.radius = radius;
this.color = color;
init();
}
private function init():void
{
with (graphics)
{
beginFill(_color, 0.6);
drawCircle(0, 0, radius);
endFill();
}
**ax = 0;
ay = 0;
vy = 0;
vx = 0;** *//It was this piece of code that I'd forgotten to include.*
addEventListener(Event.ENTER_FRAME, moveBall, false, 0, true);
addEventListener(Event.REMOVED_FROM_STAGE, removeBall, false, 0, true);
}
public function moveBall(evt:Event):void
{
vy += ay;
vx += ax;
vx *= 0.95;
vy *= 0.95;
x += vx;
y += vy;
}
private function removeBall(evt:Event):void
{
removeEventListener(Event.ENTER_FRAME, moveBall);
removeEventListener(Event.REMOVED_FROM_STAGE, removeBall);
}
public function set color(c:uint):void
{
if (c <= 0xFFFFFF)
{
_color = c;
} else
{
_color = Math.random() * 0xFFFFFF;
}
}
}
}