# AS Wave Motion

**URL:** <https://forum.kirupa.com/t/as-wave-motion/250706>\
**Category:** flash\
**Created:** [January 31, 2008, 7:13pm UTC](https://forum.kirupa.com/t/as-wave-motion/250706 "2008-01-31T19:13:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeancnicolas](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@jeancnicolas](https://forum.kirupa.com/u/jeancnicolas)\
**Post date:** [January 31, 2008, 7:13pm UTC](https://forum.kirupa.com/t/as-wave-motion/250706/1 "2008-01-31T19:13:06Z")

</div>

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’:

```auto

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:
