Flash CS3 - 360 Degree View








Move your mouse over the image

Download ThreeSixtyCS3.zip (134 KB)



ActionScript Code:

// Developed by Anil kumar N D
// anilkumarnd@gmail.com
// ActionScript 3.0
// 01-April-2009
// http://flash-workshop.blogspot.com/

package {

import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.geom.*;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.filters.DropShadowFilter;

public class ThreeSixty extends MovieClip {

var camera:Bitmap;

var textureMap:BitmapData;

var Height:int;

var Width:int;

var sourceX:int=0;

var shp_mainLine:Shape;

var shp_statusLine:Shape;

var txt_status:TextField;

var speed:Number;

 

var mc_rightButton:MovieClip;

var mc_leftButton:MovieClip;

public function ThreeSixty():void {

stage.frameRate=30;

var imageLoader:Loader=new Loader();

createStatusBar();

imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);

imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoadComplete);

imageLoader.load(new URLRequest("landscape.jpg"));

}

private function imageLoadComplete(IN_Event:Event):void {

 

removeChild(shp_mainLine);

removeChild(shp_statusLine);

removeChild(txt_status);

textureMap=IN_Event.target.content.bitmapData;

Height=textureMap.height;

Width=textureMap.width;

camera=new Bitmap ;

camera.bitmapData=new BitmapData(550,384);

addChild(camera);

stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunction);

stage.addEventListener(Event.ENTER_FRAME,moveCameraFunction);

 

mc_rightButton=createArrowKey();

mc_leftButton=createArrowKey();

mc_rightButton.rotation=180;

mc_rightButton.x=550;

mc_rightButton.scaleX=.5;

mc_rightButton.scaleY=.5;

mc_leftButton.scaleX=.5;

mc_leftButton.scaleY=.5;

addChild(mc_rightButton);

addChild(mc_leftButton);

}

function progressHandler(IN_Event:ProgressEvent):void {

var percent:Number=IN_Event.bytesLoaded*100/IN_Event.bytesTotal;

shp_statusLine.scaleX=percent/100;

txt_status.text=Math.round(percent)+" %";

}

function createStatusBar():void {

shp_mainLine = new Shape();

shp_mainLine.graphics.lineStyle(8,0x00CC00);

shp_mainLine.graphics.lineTo(200,0);

shp_mainLine.x = (stage.stageWidth/2)-(shp_mainLine.width/2);

shp_mainLine.y = (stage.stageHeight/2);

shp_statusLine = new Shape();

shp_statusLine.graphics.lineStyle(1,0xFFFFFF);

shp_statusLine.graphics.lineTo(200,0);

shp_statusLine.scaleX=.01;

shp_statusLine.x=(stage.stageWidth/2)-(shp_mainLine.width/2);

shp_statusLine.y=(stage.stageHeight/2);

txt_status = new TextField();

txt_status.autoSize=TextFieldAutoSize.CENTER;

txt_status.selectable=false;

txt_status.textColor=0x000000;

txt_status.y=shp_mainLine.y+10;

txt_status.x=shp_mainLine.x + (shp_mainLine.width/2);

addChild(shp_mainLine);

addChild(shp_statusLine);

addChild(txt_status);
}

 

function mouseMoveFunction(IN_Event:MouseEvent):void {

speed = (mouseX-(stage.stageWidth/2))/10;
}

function moveCameraFunction(IN_Event:Event):void {

sourceX += (speed);

if (speed<0&&sourceX<=0) {

sourceX=textureMap.width-550;

} else if (speed>0&&sourceX>=textureMap.width-550) {

sourceX=0;

}

camera.bitmapData.copyPixels(textureMap,new Rectangle(sourceX,0,camera.width,camera.height),new Point(0,0));

}

private function createArrowKey():MovieClip {

var ArrowKey=new MovieClip ;

ArrowKey.graphics.beginFill(0x6532FF,1);

ArrowKey.graphics.lineStyle(1,0x000000);

ArrowKey.graphics.lineTo(60,-50);

ArrowKey.graphics.lineTo(45,-5);

ArrowKey.graphics.lineTo(100,-30);

ArrowKey.graphics.lineTo(100,30);

ArrowKey.graphics.lineTo(45,15);

ArrowKey.graphics.lineTo(50,50);

ArrowKey.graphics.lineTo(0,0);

ArrowKey.y=300;

ArrowKey.buttonMode=true;

ArrowKey.filters=[new DropShadowFilter(5,10,0X000000,1,7,7,1,1)];

return (ArrowKey);
}

}

}



Comments

Popular posts from this blog

AS3 - Access objects from external SWF files

Flash CS3 - XML Guestbook (AS3)

Flash CS4 - 3D Rotating Menu