View Full Version : Very simple - how do I make a function?
roscoman
07-13-2006, 10:40 AM
This sounds absolutely ridiculous but I simply cannot get this to work. I want to have a MovieClip with a function that can be called from the main timeline that controls aspects of the MovieClip instance.
So I make a MovieClip and I put some actionscript on the first frame of the first layer:
changeFrame = function()
{
trace("calling changeFrame function");
gotoAndStop(2);
}
Then I put an instance of the MovieClip on the main stage, give the instance the name 'myInstance' and put some actionscript in the first frame of the main timeline:
_root.myInstance.changeFrame();
The function is never called. I just do not understand this. Please could someone explain what I'm doing wrong.
Many thanks
Ross
mooska
07-13-2006, 10:58 AM
use protoMovieClip.prototype.changeFrame = function(){
///bla bla bla
}
roscoman
07-13-2006, 11:10 AM
Hi Mooska
Thanks for your reply. I tried the prototype thing and it worked, but the problem was that if I had another MovieClip (an instance of a different MovieClip symbol) with the same function name, there is a strange interaction. For example:
MovieClip1 has a function:
MovieClip.prototype.changeFrame = function()
{
trace("Called changeFrame function of MovieClip1");
}
And MovieClip2 has the a function with the same name:
MovieClip.prototype.changeFrame = function()
{
trace("Called changeFrame function of MovieClip2");
}
and instances on the main stage, mc1Instance and mc2Instance. If I use:
_root.mc2Instance.changeFrame();
The output is : "Called changeFrame function of MovieClip1"
It's a strange interaction but I need to have the MovieClips having functions with the same name. I guessed it was something to do with me not really understanding what the MovieClip.prototype thing was doing.
Any other ideas?
Thanks
Ross
mooska
07-13-2006, 12:14 PM
MovieClip.prototype add a method to mc, method example is gotoAndPlay();
so after applying it, EVERY movieclip has it ;)
roscoman
07-13-2006, 02:55 PM
Well that makes sense but I don't want that to happen. I want to put a function in a MovieClip that only applies to instances of that MovieClip, not every instance of every MovieClip I make. How do I do that? It seems like such a simple and obvious thing to want to do but I just cannot work out how to do it.
Thanks
Ross
mooska
07-13-2006, 03:55 PM
this.myInstance.changeFrame = function()
{
trace("calling changeFrame function");
gotoAndStop(2);
}
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.