I'm creating a game where I need the speed of certain movie clips to speed up or slow down depending on what the player collides with or picks up. To do this I altered the value of a variable 'n' on collision etc... and then used the following script in the timeline:
if (n+_currentframe<=40) {
gotoAndPlay(_currentframe+n);
}
if (n+_currentframe>40) {
gotoAndPlay((_currentframe+n)-40);
}
I've used the IF statement as my MC is a 40 frame loop so need the clip to jump to the corresponding frame at the start of the loop if _currentframe+n is greater than 40.
THE PROBLEM is that this code causes flash problems (i get the dialogue box 'A script in your movie is causing flash to run slow - abort script?). I've tried using the script in 2 ways: in a key frame on every frame of my 40 frame MC and in a separate 2 frame MC with the code in the first frame and a goto in the 2nd frame (and inserting _root where appropriate). Whichever way I try I get the same problem...
Any suggestions very welcome as I'm getting a headache now...
is each movieclip and animation?
If so why not move each with a actionscript, and use a global or local speed value to change the rate of motion?
Not sure exactly how you have your movie setup but with the code you have, the movie would get stuck in a loop and execute multiple scripts, basically causing an inifinite loop as in an incorrectly written for or while script.
I could switch some of my animations to work as MCs controlled by the speed variable BUT there is also some shape tweening going on so I need to figure this skipping frame thing out.
out of interest, what do I need to do to make speed local to one clip or global so all clips can read it?
various ways to do the global speed rather than local. Obviously local would be contained script within the MC.
option1:
set _root.Speed variable and use this within internal script of MovieCLip. All instances will look on root for the value
option2:
MovieClip.prototype.Speed=3
This adds a speed variable to the MovieClip class, thus all movieclips will have a .Speed, just reference as this.Speed from within the movieclip
As for your frames problem, coudl you post stripped down example ?
Have to see what you have to come up with a fix/work around.
i created this just to demonstrate the problem and left in the dodgy actions so you can see the thing go wrong. the buttons just alter the value of 'n'.
I can see that you are using php as well as flash and sql. I have the same issue but not in the same context.
Could you please tell me how to set a flash background into a php page using sql data.
OK got a work around, One which may be a bit processer intensive on slower machine. However its not a bad example of how to modify the internal frame speed of a movie.
The other is a simple fix
Option1:
All code
set variable fps ( frames per second) and create an interval on 1000/fps, which gives you a time between each frame
got to next frame after this time.
Update the FPS in each button and reset interval.
Option2:
(attached next post)
Duplicate the animation and place linear on timeline. Calculate the relevent frame to go to with the faster or slower animation.
thanks, I think i'll go with option 2 to avoid affecting game play.
anychance you could post the code with a little comment so i can work out excatly what's going on...?
sPoints=[1,31,46] //start frames of each speeed section
anim=0 // reference to sPoints, indicates current animation
factor=2 // how much quicker or slower each speed section is i.e x2 1st animation=30 frames 2nd=15
//function to determine gotoFrame
function getNewFrame(newAnim)
{
//newAnim if passed from the buttons indicates next index in sPoints
newFrame=_currentframe-sPoints[anim] //get frame in relation to start point
if(newAnim>anim)
{
//if > need to divide as gets slower
//if you break this down it means
// if going from animation 1(anim) to 2(newAnim) and on frame 8 of animation 1
// 8/((2-1)*2)=4
//where the 8th frame in the first animation equates to the 4th in the next as is 1/2 the frame number (x2)
//hope that makes sense!
newFrame=Math.floor(newframe/((newAnim-Anim)*factor))
}else{
//if < need to Muliply as quicker
newFrame=Math.floor(newframe*((newAnim-Anim)*factor))
}
//set to new anim
anim=newAnim
trace(newFrame)
gotoAndPlay(newFrame)
}