# Light switch

**URL:** <https://forum.kirupa.com/t/light-switch/263102>\
**Category:** Uncategorized\
**Created:** [June 12, 2008, 4:19pm UTC](https://forum.kirupa.com/t/light-switch/263102 "2008-06-12T16:19:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ray1975](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@ray1975](https://forum.kirupa.com/u/ray1975)\
**Post date:** [June 12, 2008, 4:19pm UTC](https://forum.kirupa.com/t/light-switch/263102/1 "2008-06-12T16:19:49Z")

</div>

Hi guys,  
I’m new here and very happy to be!

I’m a beginner in Flash, nevertheless my company gave me this widget to create.  
It is basically done and I’m kind of happy with it but

- please go to  
[http://www.giuseppecraparottacv.co.uk/HTML/FLASH/mood-lighting.html](http://www.giuseppecraparottacv.co.uk/HTML/FLASH/mood-lighting.html)  
to understand what follows -

Click once on the button - click a second time - everything works fine until now.  
Now click a third time. The lighting doesn’t go back to its original status, as wanted.  
Fortunately if you click a forth time, you get what you wanted to get with the third click.

I give you an insight on the ActionScript. I coded:  
[FONT=Courier New]  
[FONT=Verdana][COLOR=Red]1)[/COLOR][/FONT]

on(release) {  
gotoAndPlay(“10”);  
}[FONT=Verdana]

for the button (not the frame) frame 1. 10 is the frame when the turn-light-down animation starts.

[/FONT][/FONT][FONT=Courier New][FONT=Verdana][COLOR=Red]2)[/COLOR][/FONT]

on(release) {  
gotoAndPlay(“30”);  
}[FONT=Verdana]

for the button (not the frame) in frame 30. 30 is the frame when the turn-light-up animation starts.

[/FONT][/FONT][FONT=Courier New][FONT=Verdana][COLOR=Red]3)[/COLOR][/FONT]

on(release) {  
gotoAndPlay(“10”);  
}[FONT=Verdana]

for the button (not the frame) in frame 50. 50 is the frame when the turn-light-up animation ends.  
This third piece is intended to let the button trace the point - back in time - in which the light goes down. I wanted to create a button-activated loop with no interruptions.  
So why does it take a forth click to have the light down again?

Thank you for your help,  
Ray  
[/FONT][/FONT]

---

<div class="post-metadata">

**Author:** ![Rik81](https://avatars.discourse-cdn.com/v4/letter/r/9fc348/32.png) [@Rik81](https://forum.kirupa.com/u/Rik81)\
**Post date:** [June 12, 2008, 4:30pm UTC](https://forum.kirupa.com/t/light-switch/263102/2 "2008-06-12T16:30:02Z")

</div>

Don’t know if I got it right, but you could create a tween with just three keyframe:

Kf 1= button that makes the animation goes dark. The tween starts and reach frame let’s say 10

Kf 10=button that makes the animation goes bright till it reach frame let’s say 19. In this final frame write the script: gotoAndStop (1)…

With my little knowledge of Actionscript, I would do like this…

---

<div class="post-metadata">

**Author:** ![glosrfc](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/glosrfc/32/8334_2.png) [@glosrfc](https://forum.kirupa.com/u/glosrfc)\
**Post date:** [June 12, 2008, 5:33pm UTC](https://forum.kirupa.com/t/light-switch/263102/3 "2008-06-12T17:33:42Z")

</div>

Your timeline flow is wrong…

Frame 1 - lights are on - contains button to dim lights

Frame 10 - lights begin to dim - contains button to turn lights up

Frame 30 - lights are dim - contains button to turn lights up

Frame 50 - lights are on - contains button to dim lights. Try gotoAndPlay(11);

Better still use frame labels, e.g. lights\_on and lights\_off, instead of frame numbers and you should be able to understand/control where the playhead goes much more easily.
