question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't access anim endpoints from loadAnimation

See original GitHub issue

I want to change text of some of the layers in my project using the function updateDocumentData. In order to do so I want to track down the endpoints to my text objects in the json.

My plan here was to use console.log to print out the layers one by one but layers[0] returns Cannot read property of null. So after a long time of testing and head scratching I realized something is weird. I print the anim.renderer then anim.renderer.layers and then anim.renderer again.

When using layers as endpoint it returns null, but in the developer console in Chrome the other two calls returns layers with 5 elements. ( See screenshot below ). I have tried using JQUERY and waiting for document.ready and tried to access the end layer right away but it is the same problem. I also tried using let instead of var.

Thanks.

var animData = {
            container: document.getElementById('lottie'),
            renderer: 'svg',
            loop: true,
            autoplay: true,
            path: 'test1.json'
          };

          var anim = lottie.loadAnimation(animData);

          console.log(anim.renderer);
          console.log(anim.renderer.layers);
          console.log(anim.renderer);

image

EDIT - This is the current latest build ( 5.1.14 )

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

5reactions
kaysoncommented, May 17, 2018

Yes works after that, thanks!

Here is the edited code if anyone will catch the same problem:

var animData = {
    container: document.getElementById('lottie'),
    renderer: 'svg',
    loop: true,
    autoplay: false,
    path: 'test1.json'
};

var anim = lottie.loadAnimation(animData);

anim.addEventListener("DOMLoaded", function() {
    console.log(anim.renderer);
    console.log(anim.renderer.layers);
    console.log(anim.renderer);
    anim.renderer.elements[0].updateDocumentData({
        t: '111'
    });
    anim.play();
});
1reaction
NandiniNayakcommented, Oct 31, 2019

@kayson and @bodymovin thanks for sharing the solution. When I try the code snippet shared by @kayson , it resolves the undefined error, instead I get ’ Uncaught TypeError: anim.renderer.elements[0].updateDocumentData is not a function’. is updateDocumentData depricated?? …please find my code snippet, also i have console logged to ensure I am targeting the right index.

  anim.addEventListener("DOMLoaded", function () {
      console.log("BFEORE:", anim.renderer.elements[0].currentTextDocumentData.t);
      anim.renderer.elements[0].updateDocumentData({
         t: 'w'
      });
      anim.play();
      console.log("AFTER:", anim.renderer.elements[0]);
 });
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't load Animation from Catalog - DevForum | Roblox
Hello, i want to load this animation : Toy Idle - Roblox on a NPC but nothing happens.
Read more >
Creating interactive Lottie animations | Pinegrow Web Editor
Lottie are super small animation files that are scalable and can be ... In this tutorial I'll first show you how to get...
Read more >
CSE 591 Project 4: Animate - Washington
This kind of file can not be read back in to Animator. ... The "load animation" command looks in the currently loaded VRML...
Read more >
Animation in Android with Example - GeeksforGeeks
Tweened animation calculates animation information such as size, rotation, start point, and endpoint. These animations are slower and less ...
Read more >
Animation Clip - Unity - Manual
Cannot access other versions offline! Animation Clip. Switch to Scripting. Animation Clips are the smallest building blocks of animation in Unity. They ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found