# Looping through a function

**URL:** https://forum.kirupa.com/t/looping-through-a-function/195760
**Category:** Uncategorized
**Created:** [August 2, 2006, 9:59pm UTC](https://forum.kirupa.com/t/looping-through-a-function/195760 "2006-08-02T21:59:09Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![davedark](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@davedark](https://forum.kirupa.com/u/davedark)
#### Post date: [August 2, 2006, 9:59pm UTC](https://forum.kirupa.com/t/looping-through-a-function/195760/1 "2006-08-02T21:59:09Z")

</div>

Hello there,

I’ve created the following code that opens and closes ‘doors’. The problem I’m having now is how to repeat this code for each set of doors there are 8 of them). I presume I could use a for loop to do this however I am confused how I achieve this.

screen\_1 is the button used to open and close the doors (door\_left\_1 and door\_right\_1) using onPress and onRollout. I need this script to repeat this for each set of doors.

The only solution I’ve come up with so far is repeating the below 8 times, sure there is a more efficient way to do it!

Cheers

```
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000FF]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]Tween[/COLOR];

```

[COLOR=#0000FF]import[/COLOR] mx.[COLOR=#000080]transitions[/COLOR].[COLOR=#000080]easing[/COLOR].\*;

[COLOR=#000000] **var** [/COLOR] xpos\_left:[COLOR=#0000FF]Number[/COLOR] = door\_left\_[COLOR=#000080]1[/COLOR].[COLOR=#0000FF]_x[/COLOR];  
[COLOR=#000000] **var** [/COLOR] xpos\_right:[COLOR=#0000FF]Number[/COLOR] = door\_right_[COLOR=#000080]1[/COLOR].[COLOR=#0000FF]_x[/COLOR];  
[COLOR=#000000] **var** [/COLOR] [COLOR=#0000FF]down[/COLOR]:[COLOR=#0000FF]Boolean[/COLOR] = [COLOR=#000000] **false** [/COLOR];  
open\_em = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]down[/COLOR] = [COLOR=#000000] **true** [/COLOR];  
[COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]door\_left_[COLOR=#000080]1[/COLOR], [COLOR=#FF0000]"_x"[/COLOR], Bounce.[COLOR=#000080]easeOut[/COLOR], xpos\_left, xpos\_left-[COLOR=#000080]48[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]door\_right_[COLOR=#000080]1[/COLOR], [COLOR=#FF0000]"_x"[/COLOR], Bounce.[COLOR=#000080]easeOut[/COLOR], xpos\_right, xpos\_right+[COLOR=#000080]48[/COLOR], [COLOR=#000080]1[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000]}[/COLOR];  
close\_em = [COLOR=#000000] **function** [/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000FF]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]door\_left_[COLOR=#000080]1[/COLOR], [COLOR=#FF0000]"_x"[/COLOR], Bounce.[COLOR=#000080]easeOut[/COLOR], xpos\_left-[COLOR=#000080]48[/COLOR], xpos\_left, [COLOR=#000080]1[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#000000] **new** [/COLOR] Tween[COLOR=#000000]([/COLOR]door\_right_[COLOR=#000080]1[/COLOR], [COLOR=#FF0000]"_x"[/COLOR], Bounce.[COLOR=#000080]easeOut[/COLOR], xpos\_right+[COLOR=#000080]48[/COLOR], xpos\_right, [COLOR=#000080]1[/COLOR].[COLOR=#000080]5[/COLOR], [COLOR=#000000] **true** [/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#0000FF]down[/COLOR] = [COLOR=#000000] **false** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR];  
screen_[COLOR=#000080]1[/COLOR].[COLOR=#0000FF]onPress[/COLOR] = [COLOR=#000000] **function** [/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
open\_em COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR];  
screen\_[COLOR=#000080]1[/COLOR].[COLOR=#0000FF]onRollOut[/COLOR] = [COLOR=#000000] **function** [/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
close\_em COLOR=#000000[/COLOR];  
[COLOR=#000000]}[/COLOR];  
[/LEFT]  
[/FONT]
