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.