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

    Code
    // 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

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


    to virtualtour.xml

    Code
    <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!

  • 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.

  • 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

  • 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.

  • 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

  • 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?

  • 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).

  • Update: I added passQueryParameters to my javascript.

    PHP
    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.

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

    Code
    viewer.passQueryParameters();

    and still getting a Loading Failed (400) error.

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

    PHP

    Code
    if (isset($_GET['VMScene']))	{
    	$loadVMScene = $_GET['VMScene'];
    	} else {
    	$loadVMScene = "0";
    	}

    Javascript

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

    xml

    Code
    <include url="virtualtour%$VMScene%.xml"/>
  • 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

    PHP
    <?php
    	if (isset($_GET['VMScene']))	{
    	$loadVMScene = $_GET['VMScene'];
    	} else {
    	$loadVMScene = "0";
    	} ?>
    	viewer.addVariable("VMScene", <?php echo $loadVMScene; ?>);

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

  • 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

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

    Code
    <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.

  • 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!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!