AS Wave Motion

Here’s my code for trying to make a dynamic wave … It works thus far, but Im having some Maths problems. The ‘wave’ block is 30x20, stored in the library with an id of ‘wave’:


sw = Stage.width/2;
sh = Stage.height/2;
h = 22; //tile height

t = 20; //no. of tiles
rows = 4;
wlength = 20;

for(r=0;r<rows;r++){

    for(i=0; i< t; i++){
        var xPos:Number = i*22;
        
        _root.attachMovie("wave",[r]+"_mc"+*,this.getNextHighestDepth(),{_x:sw+xPos,_y:sh+(r*h)});
        //_root[r+"_mc"+i].duplicateMovieClip([r]+"b_mc"+i,this.getNextHighestDepth(),{_x:sw-h-xPos,_y:sh+(r*h)});  this is for the other side of the wave, which needs to be 'mirrored' .. but first things first..
        
        _root[r+"_mc"+i].onEnterFrame = function(){
            
            var wave:Number = (this._x/sw)*wlength;
            this._y += (_root._ymouse-i*h)/wave;
        }
    } 
};

If Anyone can help - it would be awesome - Ive just got my numbers crossed now :bandit: