You are not logged in.

Dear visitor, welcome to krpano.com Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Tuesday, September 17th 2013, 10:36pm

Variable not passing correctly, [object Object]

I'm attempting to dynamically add the ability to load a specific scene by passing a variable through the URL. (E.G. http://domain.com/tour.php?scene=1) Everything seems to be working fine up until I try to have the xml file parse the variable; it returns "[object Object]" instead of the value I'm passing.

Here's the pertinent code:
PHP

Source code

1
2
3
4
5
6
// Grab the variable from the URL. If not present, default to scene 0
if (isset($_GET['scene']))	{
	$loadScene = $_GET['scene'];	
} else {
	$loadScene = "0";	
}



to Javascript

Source code

1
2
3
4
// Create Viewer
var viewer = createPanoViewer({swf:"virtualtour.swf", xml:"virtualtour.xml", target:"panoDIV"});
viewer.addVariable("scene", '<?php echo $loadScene; ?>');
viewer.embed();



to virtualtour.xml

Source code

1
<include url="virtualtour%$scene%.xml"/>



results in "FATAL ERROR: virtualtour[object Object].xml - loading failed! (404)" ... which makes sense because, well, that file doesn't exist. *tongue*

Any ideas why the variable doesn't pass through correctly? Thanks!

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

2

Wednesday, September 18th 2013, 12:49am

pretty sure you can't use variables in the include part.

Have your xml be a php and pass a php variable so that it works that way.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

3

Wednesday, September 18th 2013, 1:40am

Thanks for the reply!

I've seen posts where people pass variables into the include, most commonly as a cache buster. Perhaps I'm missing a step somewhere?

That method would work, but unfortunately not in my case. It would require a HUGE overhaul/rewrite for my client and that's just not currently feasible.

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

4

Wednesday, September 18th 2013, 2:26am

Normally, your scenes should be your main xml. And everything else is your include.
Since your index is php, its easy to point to your different xml right there.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

5

Wednesday, September 18th 2013, 3:15am

The way it's been set up, the chrome and scenes are in a separate xml files. They've been using PanotourPro for a while now with a lot of tours already built. I'm trying to extend functionality further (gonna need to insert code manually into some existing tours, then use my injection points with PanotourPro's theming to have this built-in moving forward). They work like this:

index.php -- loads the main virtualtour.xml file
virtualtour.xml -- contains the stage and all the UI chrome. This also loads the first scene, virtualtour0.xml, by default via include
virtualtour#.xml -- any number of individual scenes, loaded dynamically through hotspots or a combo box

The client is looking for a way to take a multi-scene tour and be able to specify a starting point by passing that through a variable in the URL. So, for example, if they want to embed or link a tour and start with a specific scene, the could pass that with a URL structured like http://domain.com/tour.php?scene=1

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

6

Wednesday, September 18th 2013, 7:05am

That's fine.
Just do it differently. That way you can setup your php in the index file and pass it directly to your customized xml. Very simple.

index.php -- loads the individual scene xml files.
virtualtour#.xml -- any number of individual scenes, loaded dynamically through hotspots or a combo box. Before the start of the scene tags includes virtualtour.xml and startup action to load first scene if no scene specified.
virtualtour.xml -- contains the stage and all the UI chrome.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

7

Wednesday, September 18th 2013, 8:14am

Hi,
I'm attempting to dynamically add the ability to load a specific scene by passing a variable through the URL. (E.G. http://domain.com/tour.php?scene=1) Everything seems to be working fine up until I try to have the xml file parse the variable; it returns "[object Object]" instead of the value I'm passing.
The name 'scene' can't be used for a variable because that's already a predefined array (the array of <scene> elements in the xml).
Just use an other name for your variable and it should work.

Best regards,
Klaus

8

Wednesday, September 18th 2013, 7:28pm

Ha! I totally didn't even consider that. Thanks!

9

Friday, September 20th 2013, 7:57pm

Well, I finally got around to trying that and it didn't work. I renamed the variable in the php and javascript to "asdf" and made the appropriate change in the xml file. Now I'm getting a Loading Failed (400) error. Any ideas?

10

Friday, September 20th 2013, 8:05pm

More information on how I've got things set up: I'm currently running this on my dev machine with MAMP using a virtualhost, browsing with Safari in HTML5. When browsing in Chrome with Flash, I get a Loading Error (IO Error).

11

Friday, September 20th 2013, 8:24pm

Update: I added passQueryParameters to my javascript.

Source code

1
2
3
4
var viewer = createPanoViewer({swf:"virtualtour.swf", xml:"virtualtour.xml", target:"panoDIV"});
viewer.addParam(passQueryParameters, true);
viewer.addVariable("asdf", '<?php echo $loadScene; ?>');
viewer.embed();


That looks like it's starting to do the trick. When loading the page, the pano doesn't load—I just get a white viewport—but viewing the source shows the viewer div and the appropriate embed content.

12

Friday, September 20th 2013, 9:57pm

Additional note: when I pull up the error console in Safari, I get the following:

Quoted

ReferenceError: Can't find variable: passQueryParameters

13

Tuesday, September 24th 2013, 10:57pm

Well, having spent some time away from this, came to realize I was sending query parameters incorrectly. Changed that line to

Source code

1
viewer.passQueryParameters();


and still getting a Loading Failed (400) error.

Here's the revised code again in case anyone has any ideas

PHP

Source code

1
2
3
4
5
if (isset($_GET['VMScene']))	{
	$loadVMScene = $_GET['VMScene'];
	} else {
	$loadVMScene = "0";
	}


Javascript

Source code

1
2
3
4
var viewer = createPanoViewer({swf:"virtualtour.swf", xml:"virtualtour.xml", target:"panoDIV"});
viewer.passQueryParameters();
viewer.addVariable("VMScene", <?php echo $loadVMScene; ?>);
viewer.embed();


xml

Source code

1
<include url="virtualtour%$VMScene%.xml"/>

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

14

Wednesday, September 25th 2013, 5:35am

Try

viewer.addVariable("VMScene", "<?php echo $loadVMScene; ?>");
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

15

Wednesday, September 25th 2013, 11:13pm

No luck, it gives me the same Loading Failed (400) error. :-/

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

16

Thursday, September 26th 2013, 4:45am

I used your exact syntax and it worked.

passquery parameters is not needed if your are embedding the variables in that way. That's needed if you have them in the url and aren't using php to use addvariable.

Check the javascript console to see if the file is being called right or you have a bad path directory or something else.

I didn't even know this type of variable/placeholder was possible. I must have missed it in the documentation. Where is it exactly?

http://www.seeit360.com/w8/?VMScene=2

Source code

1
2
3
4
5
6
7
	<?php
	if (isset($_GET['VMScene']))	{
	$loadVMScene = $_GET['VMScene'];
	} else {
	$loadVMScene = "0";
	} ?>
	viewer.addVariable("VMScene", <?php echo $loadVMScene; ?>);


http://www.seeit360.com/w8/?VMScene=2
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

17

Friday, September 27th 2013, 12:42am

Huh. Well, now that I know it works, I just need to sort out where the disconnect is happening on my end. I pushed my code onto my server (instead of just testing on my localhost) and I'm still getting the same error. Thanks for taking the time to give it a go. I guess at this point I need to strip my code down to bare minimum to see where it fails.

I found it in the XML reference document: http://www.krpano.com/docu/xml/#url-notes

18

Friday, September 27th 2013, 1:32am

And is this how you're including the file(s)?

Source code

1
<include url="virtualtour%$VMScene%.xml"/>


I'm about to pull my hair. Haha! It just seems as though krpano isn't parsing the variable placeholder correctly in the xml for some reason.

Posts: 1,850

Occupation: Virtual Tours - Photography - Krpano developer

  • Send private message

19

Friday, September 27th 2013, 4:03am

Exactly like that.
Try to use chromes developer tools. It maybe just a path issue. Or post a link to your project or PM it to me.
Could be your krpano is older than that feature.
KRPano Developer: Portfolio ::Gigapixel Tagging Solutions - Porfolio 2 :: Facebook :: Twitter :: reddit.com/r/VirtualTour

20

Thursday, October 31st 2013, 9:22pm

After some time away—had to work on other things—I made sure the viewer was up-to-date... still no dice.

I'll post a link online and send you the test project and PM it to you in the next couple days, if you can still take a look at it. Thanks!