# Game loop

**URL:** https://forum.kirupa.com/t/game-loop/314546
**Category:** Uncategorized
**Created:** [October 1, 2010, 11:51am UTC](https://forum.kirupa.com/t/game-loop/314546 "2010-10-01T11:51:16Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://forum.kirupa.com/u/jagguy)
#### Post date: [October 1, 2010, 11:51am UTC](https://forum.kirupa.com/t/game-loop/314546/1 "2010-10-01T11:51:16Z")

</div>

I am new to AS3 and come from .net background

I can move an image with a mouse and use a class to load the image .  
It works.  
q1)how do i put this code in a game loop in .fla file as I need to move objects automatically? Do I use a timer or is there something better?  
q2) How do I declare an event when the image from the class ClassImg2 has been loaded? I need to know this in the .fla file.  
.fla file below  
////

```auto

var li:ClassImg2= new ClassImg2("ladybug.png",120,120);
addChild(li);

stage.addEventListener(KeyboardEvent.KEY_DOWN,doSomething);

function doSomething(e:KeyboardEvent):void
{
  
  if (e.keyCode==37) //39 is right arrow
  {
  
  trace("left pressed")
  li.moveleft();
  
  }
  
  if (e.keyCode==39) //39 is right arrow
  {
  
  trace("right pressed")
  li.moveright();
  
  }
  
  
}
 

```
