Hello everyone,

So I'm working on a university project where we're making innovative musical instruments. My idea is to have a device that you would attach to any playground toy (seesaw, swing etc.) and it would play a sound on each swing.

So after playing around with Flash, I found this preset cellphone accelerometer app, which is perfect for my project. It just misses the play sound component. Which brings me to my questions.

So the code for the app goes as follows:

Code:
import flash.events.Event;

var accelX:Number;
var accelY:Number;

var fl_Accelerometer:Accelerometer = new Accelerometer();
fl_Accelerometer.addEventListener(AccelerometerEvent.UPDATE, fl_AccelerometerUpdateHandler);
function fl_AccelerometerUpdateHandler(event:AccelerometerEvent):void
{
	accelX = event.accelerationX;
	accelY = event.accelerationY;
}

ball.addEventListener(Event.ENTER_FRAME, moveBall);
function moveBall(evt:Event){
	ball.x -= accelX*30;
	ball.y += accelY*30;
	
	if(ball.x > (480-ball.width/2)){
		ball.x = 480-ball.width/2;
	}
	if(ball.x < (0+ball.width/2)){
		ball.x = 0+ball.width/2;
	}
	if(ball.y > (800-ball.width/2)){
	   ball.y = 800-ball.width/2;
	}
	if(ball.y < (0+ball.width/2)){
		ball.y = 0+ball.width/2;
	}
}
I changed the form of "ball" to a long line. I want it to play a sound each time that line hits the middle of the screen. So we're only using the x-coordinates (I think).

I figured a simple if-function should do the trick. Which I think would look something like this:

Code:
if(ball.x = 0)
{
sound.play();
}
So I have several question:
- Is that code correct?
- Where do I put the code?
- Is it possible to have a delay? So it doesn't spam-play the sound when I put the phone flat on the table where the "ball" is constantly hitting that middle line.

I'd also like to be able to change the sound. But that's optional, I'll skip it if it's too complicated.

I'd appreciate it if anyone would wanna help me.