I am attempting to write a code that will do the following:
- Produce a ball at the far right of the screen and have it move to the left.
- when the ball hits the left side of the screen, have it be replaced with a square moving in the opposite direction. (When the square hits the right side of the screen, it will change to the ball.)
- when the spacebar is hit, everything should reset itself to step 1.
My code looks like this (ball box are my movie clips):
function spawn(){
attachMovie(“ball”, “ball”, 1, {_x:550, _y:200});
};
function AI(){
ball._x -=1;
box._x +=1;
if(ball._x<=0){
removeMovieClip(ball);
attachMovie(“box”, “box”, 1, {_x:0, _y:200});
};
if(box._x>=550){
removeMovieClip(box);
attachMovieClip(ball);
};
};
function reset(){
if(Key.isDown(Key.SPACE)){
removeMovieClip(ball);
removeMovieClip(box);
attachMovie(“ball”, “ball”, 1, {_x:0, _y:200});
};
};
this.onEnterFrame = function(){
spawn();
AI();
reset();
};
What happens is that the ball forms at the correct location, but it does not move.
What am I doing wrong?