[SOLVED] Button inside movie clip to call function in main timeline
Hello again.
I'm having a bit of a hard time with calling a function in the main timeline through a button in a movieclip. Is there anyway I can make this happen?
The mc is in the main timeline and in it I added a button with this.removeMovieClip(); and so far it works, but when I try to call a function from the main timeline it just doesn't seem to work.
Thank you in advance
Last edited by Mylo Farmer; 10-06-2010 at 01:14 PM.
Reason: Solved
This will make sure my_btn exists.
Obviously the code and my_mc have to exist at the same time.
Another alternative is using the first piece of code, and make both my_mc and my_btn exist, but hide my_btn by placing it out of the stage. (one keyframe out of stage, another keyframe in the desired position).
Another alternative is using the first piece of code, and make both my_mc and my_btn exist, but hide my_btn by placing it out of the stage. (one keyframe out of stage, another keyframe in the desired position).
Thank you for the reply, Nuno. As a matter of fact, I didn't quite understand this part. What exactly would be putting a keyframe out of the stage? Do you mean in the library?
Thank you for the examples, but neither work for me. Would you have a look at my fla to see if there's nothing blocking this code? (note, I removed any code to this button).
It is on layer "desistir", mc name is "telasair" and bt is "botaosair".
You're attaching the MovieClip via attachMovie().
You'll have to add the code after the MovieClip is attached.
The layer you mention (desistir) also has that MovieClip, but that's not the one which is used as it doesn't even exist on frame 5.
Thank you for having a look at it. So you mean that if I add the code straight after the attachMovie() and move layer desistir to frame 5 I might have a chance at it?
Would the code look something like this?
Code:
_root.leaveBtn.onRelease = function ()
{
para_sons();
_root.attachMovie("sairjogo", "saindo", 755);
_root.saindo._x = 0;
_root.saindo._y = 0;
quitgame = function ()
{
i = 0;
for (;;)
{
if (i >= nitens)
{
return;
}
bloco["mc" + (i + 1)].campo.type = "dynamic";
bloco["mc" + (i + 1)].campo.tabEnabled = false;
if (bloco["mc" + (i + 1)]._currentframe != 2)
{
bloco["mc" + (i + 1)].resp = bloco["mc" + (i + 1)].valid[0];
bloco["mc" + (i + 1)].gotoAndStop(4);
}
++i;
}
}
;
telasair.onEnterFrame = function()
{
if (this.botaosair != undefined)
{
this.botaosair.onRelease = function()
{
trace("button clicked");
quitgame();
};
delete this.onEnterFrame;
}
};
}