[FlashMX]Animating with ActionScript

Hi,

I’m just venturing into Flash MX action script. Could you please give me an example of code for the following?

  • Changing Movie Clip Properties over time
  • Stopping the animation on Enter Frame
  • Stopping the animation after a certain time period

Should you know any sites that gives examples on the above, kindly state the complete URL. I sincerely appreciate your help. Thanks! :smirk:

Have you searched Kirupa tutorials and forums?

Stopping an animation using frames. Just add this code to the frame you want to stop your animation:

  
yourMovieClip.stop();

Stopping an animation using getTimer():

  
onClipEvent (enterFrame) {
	timer = getTimer();
	if (timer >= 10000) {
		yourMovieClip.stop();
	}
}

getTimer() is in milliseconds

Hi ViNc3,

Thanks for your reply. Do you have any links for the first query ie Changing Movie Clip Properties over time? I also have a question on Flash Form and ASP.
Please help

THanks again! :slight_smile:

What kind of properties?

maybe this?

http://www.kirupa.com/developer/flash5/setproperty.htm

I think you mean something like this:


onClipEvent(enterFrame) {
this._alpha -= 1;
}
//this will fade the movie clip out slowly
//this goes on the movie clips actions (not frame actions)

:cap: Jeremy

Hi everyone,

Thanks for your reply. Let me elaborate on the animation that I want to acheive. Perhaps you can give me some ideas on how to write the code.

I created a movie clip called “circles” (instance name) in Layer 1. I want it to:

a) rotate 45 degrees and fade by 10% every 1 minute. My movie rate is 12 fps.
b) stop fading and rotating after 10 minutes

Then on Layer 2 I’ve another movie clip called “train” (instance name). I want it to:

c) Move to the right, grow according to user interaction, maybe button clicks or mouse movements

d) Stop growing when it is 200 pixels wide and 200 pixels high.

 
circle.onEnterFrame=function() {
	timer = getTimer();
	if (timer < 600000)  //10 mins
		this._rotation = 45
		this._alpha = this._alpha*1/10
	else delete this.onEnterFrame;
}

I think that’s right…not sure about the math of the alpha part though
http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm

put this on the timeline of where your movieclip is:

 
dup = function() {
	timer = getTimer();
	trace("time = "+timer);
	if (timer<600000) { //600 000 millisec = 10 min
		circle._rotation += 45;
		trace("rotation = "+circle._rotation);
		circle._alpha -= circle._alpha/10;
		trace("alpha = "+circle._alpha);
 
	} else {
		delete dup;
		clearInterval (timer)
}
};
timer = setInterval(dup, 60000); //60000 millisec = 1 min

You have to wait ages to see it happen though (1 min) :stuck_out_tongue:

Bibliography:
Dynamic Event Handlers by ilyas usal
setInterval by Senocular :sen:

:slight_smile:

wouldn’t you want it to be happening constantly? (ie it fades the whole 10% over that one minute period) or did I missunderstand?


onClipEvent(load) {
    stoptime = 600; //seconds to stop effect
    //stopmiltime = 600000; //miliseconds till stop - commented out due to use of seconds instead
    time = 60; //seconds to happen over
    //miltime = 60000; //miliseconds for effect - commented out because I decided to use seconds
    framerate = 12; //framerate
 
    n = 0; //just a counter to stop effect
 
    frames = time*framerate; //convert seconds to frames
    //frames = (miltime/1000)*framerate; //uses miliseconds instead of seconds (if thats what you need)
    stopframes = stoptime*framerate; //number of frames to stop in
    //stopframes = (stopmiltime/1000)*framerate; //miliseconds instead of seconds if thats what you need
}
onClipEvent(enterFrame) {
    if(n < stopframes) {
        this._alpha -= 10/frames; //take away the alpha
        this._rotation += 45/frames; //add the rotation
        n++;
    }
}

That code will make the effect happen slowly over the whole minute. I got the impression thats what you needed. I also commenyted out the options to use miliseconds instead of seconds. Hope this all makes sense. It was kinda messy and quick (note: this goes on the Actions for the Circle clip)

Hi VinC3 and jerez_z,

Thanks for the reply. I’ve solved the following:
a)rotate 45 degrees and fade by 10% every 1 minute. My movie rate is 12 fps.
b) stop fading and rotating after 10 minutes

With your help, of course. Thanks! :slight_smile:

Now, the thing that I don’t understand is how to change the animation based on button clicks.

Is there anyway to set the getTimer value to zero?

If it’s not much trouble, could you please check the codes in the attachment
(frog1.fla) and highlight what I’m doing wrong? Thanks, again.

well no… but I’m assuming you want to restart the effect and can’t just use the same code, so what you should is change VinC3’s code slightly (sorry VinC3, maybe you shoulda done this bit):


dup = function(stime) { //stime is the value of getTimer when the function started
    trace("time = "+timer);
    if (600000>getTimer()-stime) { //this checks if the current "time" is ten minutes (in miliseconds) past the start time
        circle._rotation += 45;
        trace("rotation = "+circle._rotation);
        circle._alpha -= circle._alpha/10;
        trace("alpha = "+circle._alpha);

    } else {
        delete dup;
        clearInterval (timer)
}
};
stimer = getTimer(); //this is a value that won't change while the function goes and therefore is the start time
timer = setInterval(dup, 60000, stimer); //we sent the 'stimer' variable as a parameter of the function

this sould help:
http://www.bit-101.com/tutorials/gravity.html
or this:
http://www.bit-101.com/tutorials/
i’m sure it will help you…
i learned a lot from those links…