This maybe a simple problem, but i’m quite new to action script…
I’m creating a portfolio style web site, and would like to have the image of a character’s head on it that occasionaly blinks, and possibly moves his eyes.
I know I could create a MC of the eyes blinking, every 20 frames or something, but i wondered if there is an action script solution, where by I could create a short MC of the blinking action and get it to play the MC every minute or so, or even better at random times?
you could make an mc of the eyes blinking. then use this AS for the MC:[AS]onClipEvent(enterFrame){
blinking = Math.random()1*1000; // pick a random number between 1 and 1000
if((blinking>100) and (blinking<200)){ // if blinking is between 100 and 200
this.gotoAndPlay(2); // frame 2 is the blinking animation
}
}[/AS]you could of course change how often it blinks by decreasing the span (in this case 100-200) or changing the frame rate. or changing the range of numbers to draw a random # from.
Thanks for the help, i understand the principal, but i cant get the AS to work, Flash says there are errors like a missing ‘;’ on line 2 - i don’t understand!
onClipEvent(enterFrame){
blinking = Math.random()1*1000;
if((blinking>100) and (blinking<200)){
this.gotoAndPlay(2);
}
}
Am I applying the AS to the blinking MC?
In the MC on frame 1, do I place AS:
gotoAndPlay (1);
so that it loops, and as the blinking animation is from frame 2 onwards, it will not play it unless it meets the conditions in the top AS?
yeah, i made a typo in the AS. should be:[AS]onClipEvent(enterFrame){
blinking = Math.random()*1000+1;
if((blinking>100) and (blinking<200)){
this.gotoAndPlay(2);
}
}[/AS]
in the MC, on frame 1, place stop(); that way it will stop on frame 1 of the MC (not play the animation), until told to play the animation by the condition being met.
this should work:[AS]onClipEvent(enterFrame){
blinking = Math.random()*1000+1;
if((blinking>100) and (blinking<200) and (this._currentframe==1)){
this.gotoAndPlay(2);
}
}[/AS]this way, it won’t gotoAndPlay(2) unless the mc is currently stopped in frame 1. when the conditions are met, the animation in the MC will gotoAndPlay(2) then will eventually stop; back at 1. then it will be able to play again when the blinking conditions are met.
Thanks so much for your help bwh2, here’s the fla.
ok this is just a simple test animation, so i can get the mechanics working before I do it properly.
Basically the animation is complete when the red circle has moved back to its starting position. However, It does not always do this, sometimes it stops playing half way thru, ie: the screen goes back to white before the animation cycle has finished.
ok. i looked at your fla and i am just confused why you have 59 frames of nothing happening. i think you were trying to create the “loop” (so that the onEventClip(enterFrame) works. actually though, that “loop” will be set by your fps.
basically, you have 2 options.
delete those first 59 frames and make the AS in the remaining frame stop();
make the keyframe (frame 60) in the animation layer a regular frame. make the AS for it stop();
the keyframe (frame 60) is what’s causing the problem. the keyframe means that the mc reloads. so if it reloads in frame 60, but at that time is in the middle of an animation, the animation will stop mid-stride and restart. making it a regular frame will allow the animation to complete.
i would recommend doing option 1 because those other 59 frames are just unnecessary and you can clean things up by deleting them.
I thought that i needed the sixty frames for the animation to play out in, or otherwise it would just restart as soon as it hit frame 2, and unless it had a go to frame 1 at the end, then it would not play the AS again.
Hmmm… just when I thought I was getting to understand AS.
Thank you so much for your time and help, its much appreciated. Everyone here is so helpfull, what a great place!