_global.abutton.onRelease

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!

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


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

Why do you need to use _global?

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() {

}

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

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?

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

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).

_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…

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 ???

You can use a prototype function, a la:


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

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

:slight_smile: