# \[FlashMX\]Animating with ActionScript

**URL:** <https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822>\
**Category:** flash\
**Created:** [August 4, 2004, 4:18am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822 "2004-08-04T04:18:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdass](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mdass](https://forum.kirupa.com/u/mdass)\
**Post date:** [August 4, 2004, 4:18am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/1 "2004-08-04T04:18:46Z")

</div>

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! 😏

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2004, 12:44pm UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/2 "2004-08-04T12:44:23Z")

</div>

Have you searched Kirupa tutorials and forums?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 4, 2004, 12:49pm UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/3 "2004-08-04T12:49:22Z")

</div>

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

```php
  
yourMovieClip.stop();

```

Stopping an animation using getTimer():

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

```

getTimer() is in milliseconds

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2004, 3:55am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/4 "2004-08-11T03:55:33Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2004, 7:19am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/5 "2004-08-11T07:19:02Z")

</div>

What kind of properties?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2004, 7:29am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/6 "2004-08-11T07:29:23Z")

</div>

maybe this?

[http://www.kirupa.com/developer/flash5/setproperty.htm](http://www.kirupa.com/developer/flash5/setproperty.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 11, 2004, 10:02pm UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/7 "2004-08-11T22:02:28Z")

</div>

I think you mean something like this:

```auto

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 2:17am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/8 "2004-08-12T02:17:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 8:32am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/9 "2004-08-12T08:32:39Z")

</div>

```php
 
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](http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 8:50am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/10 "2004-08-12T08:50:34Z")

</div>

put this on the timeline of where your movieclip is:

```php
 
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) 😛

Bibliography:  
[Dynamic Event Handlers](http://www.kirupa.com/developer/actionscript/tricks/dynamicevent.htm) by ilyas usal  
[setInterval](http://www.kirupa.com/developer/actionscript/setinterval2.htm) by Senocular :sen:

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 12, 2004, 1:50pm UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/11 "2004-08-12T13:50:17Z")

</div>

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

```auto

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)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 4:04am UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/12 "2004-08-13T04:04:04Z")

</div>

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! 🙂

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 1:50pm UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/13 "2004-08-13T13:50:41Z")

</div>

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):

```auto

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

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 13, 2004, 3:08pm UTC](https://forum.kirupa.com/t/flashmx-animating-with-actionscript/59822/14 "2004-08-13T15:08:59Z")

</div>

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