8195mike
8195mike

Reputation: 90

Aframe .setAttribute() of an entity that has multiples of that component

given an entity

<a-entity animation__foo="" animation__bar""> </a-entity>

I would like to

entity.setAttribute("animation__foo", "enabled: false;");
entity.setAttribute("animation__bar", "enabled: false;");

what is the proper syntax to do this? and is it possible to set the attributes at the same time in a single command?

Upvotes: 1

Views: 2475

Answers (1)

Piotr Adam Milewski
Piotr Adam Milewski

Reputation: 14665

From the source code:

setAttribute can:
1. Set a single property of a multi-property component.
2. Set multiple properties of a multi-property component.
3. Replace properties of a multi-property component.
4. Set a value for a single-property component, mixin, or normal HTML attribute.

So, for a single property change, just do

entity.setAttribute("animation__foo", "enabled", "false;");

for multiple properties, try

entity.setAttribute("foo", {
    "one": "foo",
    "two": "bar"})

Example here.


If you want to update multiple components with one setAttribute(), it's not possible.

Upvotes: 3

Related Questions