# How to reverse the motion in that code

**URL:** <https://forum.kirupa.com/t/how-to-reverse-the-motion-in-that-code/82387>\
**Category:** flash\
**Created:** [March 10, 2005, 12:43am UTC](https://forum.kirupa.com/t/how-to-reverse-the-motion-in-that-code/82387 "2005-03-10T00:43:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vincentFX](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/vincentfx/32/446_2.png) [@vincentFX](https://forum.kirupa.com/u/vincentFX)\
**Post date:** [March 10, 2005, 12:43am UTC](https://forum.kirupa.com/t/how-to-reverse-the-motion-in-that-code/82387/1 "2005-03-10T00:43:51Z")

</div>

Hi there, I think I’m an idiot because I can’t with this, that AS put leafs in the screen and move them on X axis from left to right, and I want the opposite, from right to left, and I can’t fix the code, I thought the key was to change this:

```auto
moveLeaf = function () { this._x += this.speed;if (this._x>SW+10) {this._x = -10;}};

```

into this:

```auto
moveLeaf = function () { this._x -= this.speed;if (this._x>SW+10) {this._x = -10;}};

```

with that the movement goes from right to left just as I want but, when all the leafs appears on the screen, it stops from creating more.

Here is the entire code:

```auto
kNbrLeaves = 15;
kLeafLayer = 100;
SW = 760;
// keep track of width and height of stage
SH = 300;
// move leaves to the right
moveLeaf = function () { this._x += this.speed;if (this._x>SW+10) {this._x = -10;}};
// Initial Leaf setup
for (i=0; i<kNbrLeaves; ++i) {
    mc = _root.leafy.attachMovie('leaves', 'leaf_'+i, kLeafLayer+i);
    mc._x = random(SW);
    mc._y = random(SH);
    mc._xscale = mc._yscale=50+random(50);
    mc._alpha = 60+random(40);
    mc._rotation = random(360);
    mc.speed = random(6)+1;
    mc.onEnterFrame = moveLeaf;
}

```

Anyone can help??

Thanks a lot.
