View Full Version : function instance
MadWilson
05-30-2003, 05:29 AM
i have a function that contains actions that use this. to controll the MC's that i will be using is there a way to load a function to a MC and call up its instance name and replace this. with the MC's instance name.(multiple MC's)
function Moving_the_Ground (ground){
if (Key.isDown(Key.UP)) {
_root.Person.gotoAndStop("Walking") ;
if (_root.StopX){
this._x -= x;
}
if (_root.StopY){
this._y -= y;
} else {
_root.Person.gotoAndStop("stand_still") ;
}
Thanks
Madwilson
farafiro
05-30-2003, 05:21 PM
can u explain more what u wanna do??
senocular
05-30-2003, 05:29 PM
It looks like what you need is a prototype. This allows you to make functions that can be run for a movieclip and have this actually reference that movieclip (as if you were saying movieClipName._x etc). Similar behavior is seen in movieclip onEnterFrame and onMouseDown events.
the general idea is to make a function like you would normally, but use this format in defining it:
MovieClip.prototype.Moving_the_Ground = function(ground){
if (Key.isDown(Key.UP)) {
_root.Person.gotoAndStop("Walking") ;
if (_root.StopX){
this._x -= x;
}
if (_root.StopY){
this._y -= y;
} else {
_root.Person.gotoAndStop("stand_still") ;
}
}
}
Then you would use the function just like you would use something like swapDepths or hitTest <-- which are themselves, though maybe unbeknownst to you, prototypes for movieclips:
my_ball_mc.Moving_the_Ground(myGroundVariable);
There are more explanations about prototypes in the actionscript forum. Here are some links there:
http://www.actionscript.org/forums/showthread.php3?s=&threadid=28551
http://www.actionscript.org/forums/showthread.php3?s=&threadid=28588
searching for prototype will undoubtedly yeild more results
MadWilson
05-30-2003, 06:17 PM
Thanks it worked like a charm, but now when I load up a MC from the library it speed up the motion of the MC.
onClipEvent(enterFrame){
_root.blue.Moving_the_Ground(); //moving around
if (_root.ground._y >= 511){
trace (_root.Test_Moveie2._y);
_root.attachMovie ("Test_Movie","Test_Moveie2",1);
Moving_the_Ground ();
_root.Movie_Test._y = 300;
_root.Movie_Test._x = 200;
}
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.