# \_global.abutton.onRelease

**URL:** https://forum.kirupa.com/t/-global-abutton-onrelease/184774
**Category:** flash
**Created:** [April 7, 2006, 5:06pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774 "2006-04-07T17:06:18Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![merriamsj](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@merriamsj](https://forum.kirupa.com/u/merriamsj)
#### Post date: [April 7, 2006, 5:06pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/1 "2006-04-07T17:06:18Z")

</div>

Is it possible to do this:[INDENT][SIZE=1] make a few buttons, name them (the instance) one, two, and three  
then write a function like this

\_global.one.onRelease = function() {  
gotoAndStop(“one”,1);  
}

\_global.two.onRelease = function() {  
gotoAndStop(“one”,1);  
}

\_global.three.onRelease = function() {  
gotoAndStop(“one”,1);  
}[/SIZE]  
[/INDENT]I tried it and it doesn’t seem to work, but I wonder if I’ve just to the \_global syntax wrong… My goal is to be able to add a button called “one” anywhere in the animation, any scene, etc…, and have it call that function and work… but it doesn’t seem to this way… I know I could make one \_global function that get’s the button name using this… but I was hoping I wouldn’t have to…

any ideas would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![jwopitz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jwopitz/32/1556_2.png) [@jwopitz](https://forum.kirupa.com/u/jwopitz)
#### Post date: [April 7, 2006, 6:06pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/2 "2006-04-07T18:06:04Z")

</div>

could you explain a bit more about the scope of each button? I mean if these things are on the stage, you could just say

```auto

btn.onRelease = function () {
   got.....
}

```

Why do you need to use \_global?

---

<div class="post-metadata">

### Author: ![liquify](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@liquify](https://forum.kirupa.com/u/liquify)
#### Post date: [April 7, 2006, 6:11pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/3 "2006-04-07T18:11:47Z")

</div>

you can call your buttons anywhere… you dont need to use global… if they are on root and you want to call them from another timeline just use

\_root.one.onRelease = function() {  
…  
}

---

<div class="post-metadata">

### Author: ![jwopitz](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jwopitz/32/1556_2.png) [@jwopitz](https://forum.kirupa.com/u/jwopitz)
#### Post date: [April 7, 2006, 6:20pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/4 "2006-04-07T18:20:34Z")

</div>

to further liquify’s point:

I would not get in the habit of using \_global. If you are doing a small little thing that has a few vars here and there in which you need access to, that is one thing. But if you need access to a bunch of variables that are easily accessible by many classes, you might be better served to have a Class with Static vars that does that for you.

When people use \_global, depending on if the swf is the root level or nested, you might start running into things overwriting each others calls to the vars

Just my 2 cents

---

<div class="post-metadata">

### Author: ![merriamsj](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@merriamsj](https://forum.kirupa.com/u/merriamsj)
#### Post date: [April 7, 2006, 6:40pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/5 "2006-04-07T18:40:11Z")

</div>

Thanks for the replies…

I tried the \_root trick, but that didn’t work… not sure I really understand classes well enough to make that happen… so, jwopitz, to help make my question clearer I’d like to be able to write the function (for each button) once, in a “setup” scene, and then just have them work in the other scenes when the button is clicked (you know, because the button is named “one” or “two” or whatever the onRelease functions were written for… I(think I)'ve attached an example of this… ONE.fla (in the zip)… it has 4 scenes… a “setup” with the functions, and then three other scenes… one, two, three (with the same buttons in each, named one, two, and three)…

Just seems like I should be able to write individual functions for each, instead of a listener or something like that with a switch in it… or am I just crazy?

---

<div class="post-metadata">

### Author: ![liquify](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@liquify](https://forum.kirupa.com/u/liquify)
#### Post date: [April 7, 2006, 7:08pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/6 "2006-04-07T19:08:18Z")

</div>

do you really have to use scenes? i think i dont use scenes since flash mx… look at fla i attached

---

<div class="post-metadata">

### Author: ![merriamsj](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@merriamsj](https://forum.kirupa.com/u/merriamsj)
#### Post date: [April 7, 2006, 7:26pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/7 "2006-04-07T19:26:02Z")

</div>

LOL… Now I remember that I’ve actually done that before (like how you have it set up), on a different project, but it was not really like the project I’m thinking about now. In the project I’m thinking of there would be some fairly complex things happening after the user enters each scene… animations, question/answer fields, and lots of stuff I just would not want to set up inside of a movieclip to load in the main scene… so I guess I could just jump further along down the timeline, but scenes just seem cleaner in my book, that’s why I was looking for a way to globalize the functions… but thanks for your help all the same! Guess I need to rethink how I think! (grin).

---

<div class="post-metadata">

### Author: ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)
#### Post date: [April 7, 2006, 7:27pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/8 "2006-04-07T19:27:03Z")

</div>

\_global.one = new MovieClip;

or look at the files

---

<div class="post-metadata">

### Author: ![liquify](https://avatars.discourse-cdn.com/v4/letter/l/e95f7d/32.png) [@liquify](https://forum.kirupa.com/u/liquify)
#### Post date: [April 7, 2006, 7:39pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/9 "2006-04-07T19:39:52Z")

</div>

> [@gvozden](#):
>
> \_global.one = new MovieClip;
> 
> or look at the files

i dont think that would work with scenes… only repeating the code

one.onRelease = function() {  
trace (“yeah”);  
}

in all scenes…

---

<div class="post-metadata">

### Author: ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)
#### Post date: [April 7, 2006, 11:43pm UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/10 "2006-04-07T23:43:04Z")

</div>

you hadn’t looked the file

you can define new movie clip which will refer to your one instance movieclip  
like

\_global.oneGlobal = one;

and it will be global  
or I am wrong ???

---

<div class="post-metadata">

### Author: ![McGuffin](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mcguffin/32/408_2.png) [@McGuffin](https://forum.kirupa.com/u/McGuffin)
#### Post date: [April 8, 2006, 12:06am UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/11 "2006-04-08T00:06:15Z")

</div>

You can use a prototype function, a la:

```auto

MovieClip.prototype.button = function () {
this.onRelease = function() {
 gotoAndStop("one",1);
};
};
_global.one.button();
_global.two.button();
_global.two.button();

```

---

<div class="post-metadata">

### Author: ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)
#### Post date: [April 8, 2006, 12:16am UTC](https://forum.kirupa.com/t/-global-abutton-onrelease/184774/12 "2006-04-08T00:16:22Z")

</div>

Some clarification, MovieClips don’t exist in the \_global scope unless you use a variable to reference them as gvozden did. The \_global scope is just a regular object accessible anywhere without prepending a path.

See: [http://www.kirupa.com/forum/showthread.php?t=213473](http://www.kirupa.com/forum/showthread.php?t=213473)

🙂
