# Play an animation from main loop

**URL:** <http://forum.squareline.io/t/play-an-animation-from-main-loop/73>\
**Category:** How to\
**Created:** [February 24, 2022, 1:52am UTC](http://forum.squareline.io/t/play-an-animation-from-main-loop/73 "2022-02-24T01:52:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neodd70](http://forum.squareline.io/letter_avatar_proxy/v4/letter/n/c68b51/32.png) [@neodd70](http://forum.squareline.io/u/neodd70)\
**Post date:** [February 24, 2022, 1:52am UTC](http://forum.squareline.io/t/play-an-animation-from-main-loop/73/1 "2022-02-24T01:52:29Z")

</div>

I want to have a button so when it is pressed it toggles the checked flag and have an event that when the checked flag is checked then an animation starts and runs continuously until I click the button again which would toggle the checked state to unchecked and stop the animation.

### What have you tried so far?

Looking thru the event settings there is nothing for stopping an animation.

### Others

- **SquareLine Studio version:** 1.0.2
- **Operating system:** Windows 10
- **Target hardware:** esp32

---

<div class="post-metadata">

**Author:** ![SquareLine\_Support](http://forum.squareline.io/user_avatar/forum.squareline.io/squareline_support/32/47_2.png) [@SquareLine\_Support](http://forum.squareline.io/u/SquareLine_Support)\
**Post date:** [February 24, 2022, 1:49pm UTC](http://forum.squareline.io/t/play-an-animation-from-main-loop/73/2 "2022-02-24T13:49:38Z")

</div>

Hi,

At this moment you can do it only with custom event handlers. I created a project which shows how to do it. The magic is in `anim_while_checked_events.py`.

It looks like this:  
 ![anim_while_checked](http://forum.squareline.io/uploads/default/original/1X/36acacec7301c494e05fe744e96f0d408ace09a2.gif)

And the project:  
[anim\_while\_checked.zip](http://forum.squareline.io/uploads/short-url/xW5MIzcyafDG30XcAK8Z9ZN6jXX.zip) (9.5 KB)

---

<div class="post-metadata">

**Author:** ![dronecz](http://forum.squareline.io/letter_avatar_proxy/v4/letter/d/49beb7/32.png) [@dronecz](http://forum.squareline.io/u/dronecz)\
**Post date:** [March 30, 2022, 12:07pm UTC](http://forum.squareline.io/t/play-an-animation-from-main-loop/73/3 "2022-03-30T12:07:37Z")

</div>

Project from ZIP file should work in SLS as is it shown here or we should use it with some simulator? If I import this project and try to run it, I get this error:

![image](http://forum.squareline.io/uploads/default/original/1X/92104dae390eb8b6da5a04a521c7bb6d652ff590.png)

I tried this with SLS 1.0.4 & 1.0.5 .

---

<div class="post-metadata">

**Author:** ![SquareLine\_Support](http://forum.squareline.io/user_avatar/forum.squareline.io/squareline_support/32/47_2.png) [@SquareLine\_Support](http://forum.squareline.io/u/SquareLine_Support)\
**Post date:** [March 31, 2022, 7:49am UTC](http://forum.squareline.io/t/play-an-animation-from-main-loop/73/4 "2022-03-31T07:49:53Z")

</div>

It’s because now SLS adds `ui_` prefix to widget names to be sure they not conflict with reserved words or other variables.

All you need to do is replacing all 3 occurrences of `Panel1` with `ui_Panel1` in `anim_while_checked_events.py`.
