Uncaught TypeError: Cannot read property 'index' of undefined in tour.js

  • I am sometimes getting this issue when on the loadscene command running from javascript. Sometimes it is work find and switch between panoramas but sometimes not. Do you guys have any ideas about why this could happen? Thank you in advance.


    Code
    krpano_services.call("goto_pano('pano-scene-"+pano.id+"', 'hsp_"+$scope.local.hotspot.id+"');")
    Code
    <action name="goto_pano">
    showlog(true);
    trace(%1);
    trace(%2);
    looktohotspot(%2, 45, smooth(500,500,500));
    loadscene(%1, null, MERGE, BLEND(1));
    </action>
    Code
    INFO: krpano 1.20.6 (build 2020-04-15)
    INFO: pano-scene-16105
    INFO: hsp_25566
  • This problem was solved. The "Uncaught TypeError: Cannot read property 'index' of undefined" issue was caused that I have had set the global variable index in my dragondown action. If the 'index' global variable was changed the loadscene(%1, null, MERGE, BLEND(1)); action was bringing me that issue.

  • In JavaScript almost everything is an object, null and undefined are exceptions. This error occurs when a property is read or a function is called on an undefined variable. Undefined means that a variable has been declared but has not been assigned a value. In JavaScript, properties and functions can only belong to objects. Since undefined is not an object type, calling a function or a property on such a variable causes the TypeError: Cannot read property of undefined.

    If you are not sure a variable that will always have some value, the best practice is to check the value of variables for null or undefined before using them. To avoid getting these types of errors, you need to make sure that the variables you are trying to read do have the correct value. This can be done in various ways. You can do if checks before dealing with objects whose values are bound to change:

    "
    if (myVar !== undefined) {
    ...
    }"


    Or

    "
    if (typeof(myVar) !== 'undefined') {
    ...
    }"

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!