View Full Version : _global.button.onPress
billrm
08-24-2005, 08:40 PM
I have a series of similar but seperate movies that will use a number of the same functions. Initially I declared these in a frame on my main timeline. But rather than copy and paste from movie to movie I decided I would create a movie clip that contained these functions that I would add to each movie.
Because the functions are not on the main timeline I declared all my functions as _global. This works for everything except my button.onPress functions.
So this works in the main timeline:mc_pg_bk.onPress = function(){
mv_TL.prevFrame();}
But this does not from within my function mc:_global.mc_pg_bk.onPress = function(){
mv_TL.prevFrame();}
How can this done?
Are there better ways to make my functions portable?
Thanks.
SeanX
08-24-2005, 10:33 PM
since it's in the main timeline, have you tried _root.?instead of_global?
i somehow have a feeling _root won't work for this function.
billystyx
08-25-2005, 10:55 AM
The reason why it is a good idea to add functions to frame 1 of main timeline is that the function will then always be loaded before something tries calling it.
you can put all onPress events for the mcs inside a function - like this (on the main timeline)
function mcDoStuff(mc:MovieClip){
mc.onPress = function(){
mv_TL.prevFrame();}
}
and then call from wherever (whichever movieclip) like this:
_root.mcDoStuff(this);
billystyx
billrm
08-25-2005, 05:39 PM
I can always access it on the main timeline. Using _root should be avoided acording to Macromedia (see this MM livedocs http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00000846.html) That is the reason I define the timeline variable mv_TL by setting 'mv_TL = this;' at the begining of the movie.
I am primarily looking for a way to place common functions within a container that can be easily moved from movie to movie.
billrm
08-25-2005, 05:55 PM
I can make some global functions work from within my function mc. For example this works just fine when called from the maintimeline:
_global.testT = function(){
trace("TEST!");
}
billystyx
08-26-2005, 07:24 AM
While it is true that root is not recommended, if your movie is not going to be a part of other swf this doesn't pose a problem. However, I actually often use _level0 instead of _root, and put my code on the main timeline of the real root.
But, it is certainly (I think) a better option than adding mcs to other mc as a code holder. That will not be very accessible in the long term, and creates several different instances of the same code.
If you are looking for a way to store common functions, consider putting your code into an AS file and use include to bring it in. set the functions as global, where you import them to the main timeline. Then you should be able to use those functions throughout the swf.
billystyx
billrm
08-26-2005, 02:01 PM
Thanks Billy.
I just ordered Colin Moocks AS2.0 scripting book the other day. I had suspected that might be the direction to head.
vBulletin v3.5, Copyright ©2000-2010, Jelsoft Enterprises Ltd.