Hi everyone,
I am currently working on a website project based on flash, and I experience some issue with a function not stopping to run…I have searched a lot through internet, but could not come up with an answer.
There are several buttons on the page, with a click MouseEvent and some arguments. Here is one, which refers to the button “PortfolioButtonHereandthere” :
var newHereandthereContainer:MovieClip = new HereandthereContainer();var myfunction1;
PortfolioButtonHereandthere.addEventListener(MouseEvent.CLICK, myfunction1 = function(e:MouseEvent){load3D(e, newHereandthereContainer, 1000, 350, 500, myfunction1);});
The function load3D calls a movieclip from the library, and places it on the stage :
function load3D(e:Event, containername:MovieClip, Xposition:Number, Yposition:Number, Zposition:Number, myfunction):void{
if (containernameprevious != null) {
buttonpressed.addEventListener(MouseEvent.CLICK, mypreviousfunction);
// enables again the previous clicked button to be clicked again
this.removeChild(containernameprevious);
// removes the previous movieclip present on the stage
}
else {
}
this.addChild(containername);
// adds the movieclip on the stage
containername.x = 1000;
containername.y = 300;
containername.z = 500;
containername.alpha = .5;
// places the movieclip
mypreviousfunction = myfunction;
buttonpressed = e.target;
containernameprevious = containername;
this.addEventListener(Event.ENTER_FRAME, function(){rotate3D(containernameprevious, mypreviousfunction, buttonpressed);});
// calls a function to rotate the movieclip
}
At the end of the function, it calls another function (rotate3D) which makes the movieclip rotate :
function rotate3D(containername:MovieClip, mypreviousfunction, buttonpressed):void {
buttonpressed.removeEventListener(MouseEvent.CLICK, mypreviousfunction);
// disables the button clicked to be clicked
containername.rotationX += 1;
containername.rotationY += 1;
// rotates the movieclip continuously
}
So basically my button makes a movieclip appear on the stage through the function load3D, then makes it rotate through rotate3D. Then if you click another button, the movieclip disappears and is replaced by another one.
Everything works fine, except that the rotating function keeps on running after clicking on another button, even if the movieclip was removed, which means that if you click again on the same button, two functions will run at the same time and make my movieclip turn twice as fast…Of course, every time you click again on the button, it gets faster, which is annoying.
So does anybody know of a way I could stop my function rotate3D() currently running when I click on a button? I tried to use return, break and stop() in many ways, but nothing appeared to work…I tried with a variable, but could not figure out where to put it and what to do with it…
I’ve searched a lot and could not find anything, so your help would be greatly appreciated! I can also provide more info if needed of course.
Thank you in advance.
julien.