# \[AS3\] while condition

**URL:** <https://forum.kirupa.com/t/as3-while-condition/324461>\
**Category:** programming\
**Created:** [August 22, 2011, 1:04pm UTC](https://forum.kirupa.com/t/as3-while-condition/324461 "2011-08-22T13:04:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kestor](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kestor](https://forum.kirupa.com/u/kestor)\
**Post date:** [August 22, 2011, 1:04pm UTC](https://forum.kirupa.com/t/as3-while-condition/324461/1 "2011-08-22T13:04:10Z")

</div>

Hello again.  
Im trying to make an effect on my hero’s melee attack. Like when he hits the enemy, the enemy is thrown a bit away.  
Im trying this stuff with while, but i also tried with other things and it didnt work.  
Here is the code:

```auto

        public function knifeCollision(event:Event):void
        {
            var distance:Number=Math.sqrt( ( this.x - _r.circle.x ) * ( this.x - _r.circle.x ) + ( this.y - _r.circle.y ) * ( this.y - _r.circle.y ) );
            enemyHP=enemyHealth;
            enemyDeath=false;
            if(enemyHP>0)
            {
                if(_r.circle.circleknife.knife.hitTestObject(this))
                {
                    this.y-=30;
                    enemyHealth-=1/2;
                    this.gotoAndStop(5);
                    if(this.x>_r.circle.x)
                    {
                        while(distance<200)
                        {
                            this.x+=10;
                        }
                    }    
                    else if(this.x<_r.circle.x)
                    {    
                        while(distance<200)
                        {
                            this.x-=10;
                        }
                    }
                }
            }
            else if(enemyHP<=0)
            {
                enemyDeath=true;
                if(enemyDeath==true)
                {
                    gotoAndStop(4);
                    removeEventListener(Event.ENTER_FRAME, eFrame);
                }
            }
        }

```

The problem is that when i hit CTRL-ENTER with this code and i melee the enemy the whole program blocks.  
I also tried puting like a coordinate instead of distance, like this:

```auto

while(this.x<800)
{
     this.x+=10;
}

```

Its not good for a game but i jsut tried to see what happens, and when i hit with melee it will jsut teleport the enemy to x=800.  
I just want the enemy to smoothly be thrown to the coordinate like with speed 10.  
I also do it on Y axis after i figure the X axis.  
Also tried

```auto

do
{
     this.x+=10;
}
while (distance<200)

```

I would appreciate any help on this matter.
