# \[Question\] make the script run in every frame

**URL:** <https://forum.kirupa.com/t/question-make-the-script-run-in-every-frame/290776>\
**Category:** flash\
**Created:** [June 19, 2009, 1:41pm UTC](https://forum.kirupa.com/t/question-make-the-script-run-in-every-frame/290776 "2009-06-19T13:41:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![udi001](https://avatars.discourse-cdn.com/v4/letter/u/bc8723/32.png) [@udi001](https://forum.kirupa.com/u/udi001)\
**Post date:** [June 19, 2009, 1:41pm UTC](https://forum.kirupa.com/t/question-make-the-script-run-in-every-frame/290776/1 "2009-06-19T13:41:12Z")

</div>

Hello,

I have 2 navigation buttons (next and previous) that navigates to the next and previous frames.

acctually i have several buttons (differ by color) with the same instance name.

i have to add eventListener every time i reach a frame with a new button.

First question is why?  
if all “next” buttons have the same instance name, why doesn’t it work on all of them?

second question:  
i want to check whether there is an object in the current frame, how do i apply the code to all the frames (that will work on each frame) without dupplicating it.

> 

stop();  
import flash.events.MouseEvent;

if (pre\_btn\_insNm!==null){

pre\_btn\_insNm.addEventListener(MouseEvent.MOUSE\_DOWN,gotoPreviousFrame);

}  
if (next\_btn\_insNm!==null){  
next\_btn\_insNm.addEventListener(MouseEvent.MOUSE\_DOWN,gotoNextFrame);  
}
