# Make a function for button inside a movie clip

**URL:** <https://forum.kirupa.com/t/make-a-function-for-button-inside-a-movie-clip/297035>\
**Category:** Uncategorized\
**Created:** [September 24, 2009, 3:03pm UTC](https://forum.kirupa.com/t/make-a-function-for-button-inside-a-movie-clip/297035 "2009-09-24T15:03:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phingko](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@phingko](https://forum.kirupa.com/u/phingko)\
**Post date:** [September 24, 2009, 3:03pm UTC](https://forum.kirupa.com/t/make-a-function-for-button-inside-a-movie-clip/297035/1 "2009-09-24T15:03:26Z")

</div>

Hi all wise people

I am a noob in AS3, I hv this problem that I’ve tried to work out for his couples days  
I was asked to put all my actionscript in only at the main timeline, while I have lots of movie clips that acts as each page in my website.  
Each of them has buttons that I need to make them work without put the actionscript inside the movie clip but the main timeline.

I tried to use  
movieclip(parent).menu\_btn.function();  
which is not working

and now I’m trying to use array as a friend suggested me.

var play\_buttons:Array = new Array(“menu\_btn”, “ok\_btn”, “back3\_btn”);

stop();

//buttons for menu  
for (var i:Number = 0; i\<play\_buttons.length; i++) {  
play\_mc.menu\_btn[play\_buttons\*] = function() {  
this.gotoAndPlay(“menu”);  
};  
}

the problem is when i clicked play button and it links to the play page,but it has an intro animation for 2-3 seconds before they reach the menu\_btn  
that’s why the error come out is that I have a null object since they execute the code b4 it comes to the menu\_btn keyframe.

I think that’s my problem,no?  
If it is, do u hv any suggestion how I can fix it?

Thanks in Advance
