AS3 code for multiple panoramas

Using Pano2VR/Object2VR SWF files with your own Flash projects
Post Reply
wolfgang.amri
Posts: 3
Joined: Fri Jun 03, 2011 12:47 am
Contact:

Hi all, I used to work quite a lot in flash AS2 (no hard core programming though), but since I´ve changed my profession to photography only, I´ve become almost a flash noob it seems. I hope someone can point me in the right direction, since AS3 panos look so much better than AS2.

I´m having 9 frames on my project. The first one is a topview drawing of the place with buttons where panos are located. At the press of one of the buttons, it should send the user to the frame where this pano is imported (eg. button "pano1" should send the user to frame "pano1"). I´m using this code on the first Frame:

Code: Select all

stop();
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
/* Click to Go to Frame and Stop
Clicking on the specified symbol instance moves the playhead to the specified frame in the timeline and stops the movie.
Can be used on the main timeline or on movie clip timelines.

Instructions:
1. Replace the number 5 in the code below with the frame number you would like the playhead to move to when the symbol instance is clicked.
*/

pano1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_6);

function fl_ClickToGoToAndStopAtFrame_6(event:MouseEvent):void
{
	gotoAndStop("pano1");
}
And this one in the frame "pano1":

Code: Select all

back.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_7);

function fl_ClickToGoToAndStopAtFrame_7(event:MouseEvent):void
{
	vr.cleanup();
removeChild(loader);
	gotoAndStop("start");
}


 
var loader:Loader = new Loader();
var url:String = "360s/pano1New.swf";
var urlReq:URLRequest = new URLRequest(url);
var vr:MovieClip; // panorama movieclip
 
// This is done after the swf is loaded.
function finished_loading (e:Event) {
}
 
function initHandler(event:Event):void {
	trace("initHandler: " + event);
	vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip'
//	vr.isFlash10=false; // Disable Flash 10 rendering if the container is Flash 9
}
 
function initPanorama(e:Event) {
// check if the panorama object is available and initialize it
	if ((vr!=null) && (vr.pano!=null)) {
		removeEventListener( Event.ENTER_FRAME , initPanorama);
		vr.x=60;
		vr.y=100;
		vr.pano.setWindowSize(900,600);
	}
}
// call initPanorama every frame
addEventListener( Event.ENTER_FRAME , initPanorama);
 
// Tell the loader to call 'finished_loading' after the swf is loaded.
loader.contentLoaderInfo.addEventListener(flash.events.Event.COMPLETE, finished_loading);
// Tell the loader to call 'initHandler' after the swf is initialized.
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
loader.load(urlReq);
addChild(loader); // add your swf directly to the stage
Now if I add the same code (except for changing the line "var url:String = "360s/pano1New.swf";" to the right swf)

I get the following compiler error when exporting:

Code: Select all

Scene 1, Layer 'actions', Frame 3, Line 1	1151: A conflict exists with definition loader in namespace internal.
Scene 1, Layer 'actions', Frame 3, Line 2	1151: A conflict exists with definition url in namespace internal.
Scene 1, Layer 'actions', Frame 3, Line 3	1151: A conflict exists with definition urlReq in namespace internal.
Scene 1, Layer 'actions', Frame 3, Line 4	1151: A conflict exists with definition vr in namespace internal.
Scene 1, Layer 'actions', Frame 3, Line 7	1021: Duplicate function definition.
Scene 1, Layer 'actions', Frame 3, Line 10	1021: Duplicate function definition.
Scene 1, Layer 'actions', Frame 3, Line 16	1021: Duplicate function definition.
Could anybody please point me in the right direction?
Noisy
Posts: 35
Joined: Wed Apr 04, 2007 12:49 am
Location: Scotland

If you are putting copies of the same code on different frames then you are defining your functions and variables more than once. Put your function and variable definitions all on the first frame and call them from the frames as required.

for example on frame 1 you would define the variable for your loader
var loader:Loader;
then on whatever frame you wanted to , assign a new loader to the variable.
loader = new Loader();

OR
Change the function names and calls in each frame so that they are all different
wolfgang.amri
Posts: 3
Joined: Fri Jun 03, 2011 12:47 am
Contact:

Hi Noisy,
thanks a lot for the tips. If I only knew what function names and calls are in this code. I tried several things, but didn´t achieve any working result.

Would you be willing to change the code for me so that it works? I´d be willing to pay for your services since I guess it would cost me a lot of time to read myself into all this again.
Noisy
Posts: 35
Joined: Wed Apr 04, 2007 12:49 am
Location: Scotland

Well I can have a look at it but don't promise anything, no charge, it's interesting to look at other peoples code if there isn't too much of it. I'll pm my address and you can send me all the files. But what version of flash are you using as if the formats after cs3 I can't open them!
wolfgang.amri
Posts: 3
Joined: Fri Jun 03, 2011 12:47 am
Contact:

Hey there,
thanks a big lot, that´s very much appreciated!!!
I´ll send you an Email!

Thanks again and all the best,
Wolfgang
Post Reply