Copy link to clipboard
Copied
I am trying to finish a small project and am having trouble continuosly rotating a duplicated movieclip via a button. It will rotate by clicking the button; however, I have it set to 7.5 degrees and a complete rotation takes quite a while. We would like to just click and hold to rotate it. Once the button is released it would stop. Any help would be very much appreciated. My code is below:
MovieClip (myMC):
on (press) {
startDrag("", false);
}
on (release) {
stopDrag();
}
on (release) {
setProperty("/rotate", _name, "");
setProperty("", _name, "rotate");
}
Rotate Button:
on (press) {
ChangeRotation = getProperty("/rotate", _rotation);
setProperty("/rotate", _rotation, Number(ChangeRotation) -7.5);
}
Button used to Duplicate the movieclip:
on (release) {
_root.myMC.duplicateMovieClip ("myMC_"+ "x",this.getNextHighestDepth());
setProperty ("myMC_"+"x", _x, 585);
setProperty ("myMC_"+"x", _y, 400);
x++;
}
Copy link to clipboard
Copied
Initiate an onEnterFrame function when the rotate button is pressed and delete it when that button is released. Have the onEnterFrame processing handle the change in rotation value.
The onEnterFrame function executes at the frame rate of your file, so whatever processing you put in the function for it executes continuously.
You should consider moving up to AS2 at least for your coding. It will reduce your code and bring you one step closer to modern Flash programming. And you should get the code off of the objects and place it in the timeline instead.
Copy link to clipboard
Copied
Thank you for your help Ned. I saw a sample file for a rotation that included the onEnterFrame but honestly I am far from a computer programmer. In fact, I've pretty gotten where I am by searching and manipulating other files.
That being said, I am really not sure how exactly to adapt the function to the buttons/movieclips that are duplicated.
If not too much of an inconvenience, would it be possible to ask for a little assistance? I've gotten to a point where everything functions well but am just trying to tighten it up a little.
Thanks again for your time.
Copy link to clipboard
Copied
Here's a link to a sample file I made to show you how to use the onEnterFrame to make the object spin while you press the button. Notice how the code is in the timeline rather than on the objects, and how the properties are assigned directly rather than using setProperty...
Copy link to clipboard
Copied
Hi Ned, thank you very much for the help. I can't seem to get it to work though. Possibly because I am trying with a duplicated movieclip. I need to get this completed by the end of the week. May I contact you directly and we can discuss this further? I understand your time is valuable and would be willing to discuss that portion as well.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now