This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Darin Dimitrov
Posted Apr 08 - Read on Facebook

Hey guys, weird problem with the delay Utility here. On line 90, I'm trying to destroy a layer after it's been put out of sight (pretty standard stuff). It works great without the delay, but when wrap it in a Utils.delay, it starts applying to another layer. It's probably something scope related. Here's the code:
http://share.framerjs.com/0qccqnqerprm/

5 Comments

Kevyn Arnott

Yeah, it's a scope thing. Utils.delay can look misleading with for loops. Because of the indexing of a for loop happens at run time, if your rely on the index to call a layer you'll always end up with the last index because the for loop will cycle through all indexes, and when the Utils.delay function is called it'll refer to i and i will be the last index. To fix the problem, you'll want to capture the index and use that variable for the utils. So add something like "layer = i", and refer to layer. Here's the updated code -http://share.framerjs.com/z5zxh8nhfazc/

Ben Rodenhäuser

But then I don't get why it ends up destroying two layers (try destroying Wolverine).

Kevyn Arnott

Ben Rodenhäuser Wolverine is being hidden. The animation which isn't in the Utils.delay is hiding it, and the Utils.delay is destroying the other layer.

Ben Rodenhäuser

ah, I see! Thanks

Darin Dimitrov

Thanks, Kevyn. I'd have never known, this is extremely valuable.

Read the entire post on Facebook