0
votes

I have several entities in my a-scene and I want to hide them, if I click on a button. That my JS for changing the attribute "visible":

    <script>
      document.querySelector('#button-right').addEventListener('mouseclick',myEventHandler); 

      myEventHandler: function (evt) {
        let myEl = document.querySelector("#links");
        myEl.setAttribute('visible',"false");
    }
    </script>

The script should be executed if "button_right" is clicked:

<!-- left and right button: button-left = reset background // button-right = hide links -->
<a-entity id="buttons" layout="type: line; margin: 2.5" position="-1.75 -2.5 -4">
  <a-entity id="button-left" template="src: #button_reset" data-src="#default"></a-entity>
  <a-entity id="button-right" template="src: #button_hide"></a-entity>
</a-entity>

If I click the right button I get this error:

Uncaught DOMException: Failed to execute 'setAttribute' on 'Element': '0' is not a valid attribute name. at HTMLElement.setAttribute (http://127.0.0.1:5500/assets/js/aframe-master.js:77507:51) at HTMLElement.setAttribute (http://127.0.0.1:5500/assets/js/aframe-master.js:76931:40) at NewComponent.module.exports.setComponentProperty (http://127.0.0.1:5500/assets/js/aframe-master.js:83857:6) at HTMLElement.s (https://unpkg.com/[email protected]/dist/aframe-event-set-component.min.js:1:1990) at HTMLElement.emit (http://127.0.0.1:5500/assets/js/aframe-master.js:77546:16) at NewComponent.twoWayEmit (http://127.0.0.1:5500/assets/js/aframe-master.js:68002:19) at NewComponent.onCursorUp (http://127.0.0.1:5500/assets/js/aframe-master.js:67858:12) at HTMLCanvasElement.bound (http://127.0.0.1:5500/assets/js/aframe-master.js:83391:17)

Here is the full code:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>360&deg; Image</title>
  <meta name="description" content="360&deg; Image - A-Frame">
  <script src="assets/js/aframe-master.js"></script>
  <script src="assets/js/play-all-model-animations.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/aframe-template-component.min.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/aframe-layout-component.min.js"></script>
  <script src="https://unpkg.com/[email protected]/dist/aframe-event-set-component.min.js"></script>



</head>

<body>

  <a-scene>
    <a-assets>
      <!-- background images -->
      <img id="oberkirch" src="assets/image/oberkirch.jpg" alt="360 Degree view of the City Oberkirch">
      <img id="schauenburg" src="assets/image/schauenburg.JPG" alt="360 Degree view of the Schauenburg">
      <img id="city" src="assets/image/360_background.jpg" alt="360 Degree view of a city">
      <img id="default" crossorigin="anonymous" src="https://cdn.aframe.io/360-image-gallery-boilerplate/img/city.jpg">
      <img id="city-thumb" crossorigin="anonymous"
        src="https://cdn.aframe.io/360-image-gallery-boilerplate/img/thumb-city.jpg">
      
        <!-- Template for links -->
      <script id="circle" type="text/html">
          <a-entity class="link"
          geometry="primitive: circle; height: 1; width: 1"
          material="color: blue"
          visible="true"
          event-set__mouseenter="material.color: red"
          event-set__mouseleave="material.color: blue"
          event-set__click="_target: #image-360; _delay: 300; material.src: ${src}"
          proxy-event="event: click; to: #image-360; as: image"
          ></a-entity>
        </script>

      <!-- Template for button_reset -->
      <script id="button_reset" type="text/html">
          <a-entity class="button"
          geometry="primitive: plane; height: 0,5; width: 1s"
          material="color: blue"
          event-set__mouseenter="material.color: red"
          event-set__mouseleave="material.color: blue"
          event-set__click="_target: #image-360; _delay: 300; material.src: ${src}"
          proxy-event="event: click; to: #image-360; as: image"
          ></a-entity>
        </script>

      <!-- Template for button_hide -->
      <script id="button_hide" type="text/html">
          <a-entity class="button"
          geometry="primitive: plane; height: 0,5; width: 1s"
          material="color: blue"
          event-set__mouseenter="material.color: red"
          event-set__mouseleave="material.color: blue"
          event-set__click="_target: #link; link.setA"
          ></a-entity>
        </script>

      <!-- Script for hiding the links -->
      <script>
        document.querySelector('#button-right').addEventListener('mouseclick', myEventHandler);

        myEventHandler: function (evt) {
          let myEl = document.querySelector("#links");
          myEl.setAttribute('visible', "false");
        }
      </script>
    </a-assets>


    <!-- Change the background of the scene -->
    <a-sky id="image-360" radius="10" src="#default"></a-sky>

    <!-- Creates a cursor -->
    <a-camera>
      <a-cursor id="cursor"
        animation__click="property: scale; startEvents: click; from: 0.1 0.1 0.1; to: 1 1 1; dur: 150">
      </a-cursor>
    </a-camera>

    <!-- Links for changing the background -->
    <a-entity id="links" visible="true" layout="type: line; margin: 2.5" position="-3 -1 -4">
      <a-entity template="src: #circle" data-src="#oberkirch"></a-entity>
      <a-entity template="src: #circle" data-src="#schauenburg"></a-entity>
      <a-entity template="src: #circle" data-src="#city"></a-entity>
    </a-entity>

    <!-- left and right button: button-left = reset background // button-right = hide links -->
    <a-entity id="buttons" layout="type: line; margin: 2.5" position="-1.75 -2.5 -4">
      <a-entity id="button-left" template="src: #button_reset" data-src="#default"></a-entity>
      <a-entity id="button-right" template="src: #button_hide"></a-entity>
    </a-entity>

  </a-scene>
</body>

</html>   

Thank you!

2
Without code to run and debug it'll be hard to help. I recommend Glitch glitch.com/~aframe - Diego Marcos

2 Answers

0
votes

myEl.setAttribute('visible',false); Here true and false is a boolean value so you don't need to add as a "false" in string.

0
votes

Use single quotes ('#links') And maybe try not to use numbers for id