# How can I move an image left to right & right to left automatically?

**URL:** <https://forum.kirupa.com/t/how-can-i-move-an-image-left-to-right-right-to-left-automatically/323243>\
**Category:** flash\
**Created:** [June 22, 2011, 9:55am UTC](https://forum.kirupa.com/t/how-can-i-move-an-image-left-to-right-right-to-left-automatically/323243 "2011-06-22T09:55:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![learner\_7n](https://avatars.discourse-cdn.com/v4/letter/l/b2d939/32.png) [@learner\_7n](https://forum.kirupa.com/u/learner_7n)\
**Post date:** [June 22, 2011, 9:55am UTC](https://forum.kirupa.com/t/how-can-i-move-an-image-left-to-right-right-to-left-automatically/323243/1 "2011-06-22T09:55:06Z")

</div>

Hi,

I have an Image called “PanoramaImage” (which is very long in width). I want this image to move from right to left & from left to right automatically.

I am using flash as3. I am loading this image from the same folder where the .fla file exist. Right now I have the code which will help my image to move by using Up & Down arrow keys.

The following is the sample code i found on web.

var loader:Loader = new Loader();  
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);  
loader.load(new URLRequest(“panorama.jpg”));  
var content\_mc:Sprite = new Sprite();  
function completeHandler(event:Event):void{  
var image1:Bitmap = (Bitmap)(loader.content);  
var image2:Bitmap = new Bitmap(image1.bitmapData.clone());  
content\_mc.addChild(image1);  
content\_mc.addChild(image2);  
image1.x = 0;  
image2.x = image1.width;

addChild(content\_mc);  
content\_mc.x = 0;

stage.addEventListener(KeyboardEvent.KEY\_DOWN, keyPressed);  
}  
function keyPressed(event:KeyboardEvent):void {  
switch (event.keyCode) {  
case Keyboard.LEFT :  
content\_mc.x += 20;  
break;  
case Keyboard.RIGHT :  
content\_mc.x -= 20;  
break;  
}

if (content\_mc.x\>0) {  
content\_mc.x= -content\_mc.width /2;  
}  
else if (content\_mc.x \< stage.stageWidth - content\_mc.width){  
content\_mc.x= stage.stageWidth - content\_mc.width/2 ;  
}  
}

Please help me with the code.

Thanks.
