# Invoking a cycle in a function without rewriting it?

**URL:** https://forum.kirupa.com/t/invoking-a-cycle-in-a-function-without-rewriting-it/313650
**Category:** flash
**Created:** [September 6, 2010, 9:11am UTC](https://forum.kirupa.com/t/invoking-a-cycle-in-a-function-without-rewriting-it/313650 "2010-09-06T09:11:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![elliria](https://avatars.discourse-cdn.com/v4/letter/e/f04885/32.png) [@elliria](https://forum.kirupa.com/u/elliria)
#### Post date: [September 6, 2010, 9:11am UTC](https://forum.kirupa.com/t/invoking-a-cycle-in-a-function-without-rewriting-it/313650/1 "2010-09-06T09:11:05Z")

</div>

hello,  
i’m stuck with this problem: i have a for loop running through an array:

```auto

for (var e:int = 0; e < coo.length; e++) {
    coo[e].addEventListener(MouseEvent.ROLL_OVER, evidenzia);
    coo[e].addEventListener(MouseEvent.CLICK, evidenzia_fisso);
    coo[e].alpha = 0.4;
    }

```

but when i have to call back the cycle inside a function, it gives me error 1090 unless i repeat the cycle inside the function:

```auto

function evidenzia_fisso(event:MouseEvent):void {
    for (var e:int = 0; e < coo.length; e++) {
    coo[e].removeEventListener(MouseEvent.ROLL_OVER, evidenzia);
    coo[e].removeEventListener(MouseEvent.ROLL_OUT, n_evidenzia);
    coo[e].removeEventListener(MouseEvent.CLICK, evidenzia_fisso);
    for (var i:int = 0; i < quiqua.length; i++) {
        if (quiqua*.saturaz != event.currentTarget.saturaz){
              quiqua*.alpha = 0.2;
               }
    coo[e].addEventListener(MouseEvent.CLICK, per_ogni_click, false,0,true);
    stage.addEventListener(MouseEvent.CLICK,reset,false,0,true);
        }
    }

```

i’m recalling this cycle in a lot of functions so it’s kinda boring and confusing repeating it every time.

i tried assigning a variable to the elements:

```auto
var coo_att:MovieClip = MovieClip (coo[e]);

```

but it doesn’t work properly.

I really don’t know what to do.
