# onEnterFrame() and \_currentFrame, help please

**URL:** <https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983>\
**Category:** flash\
**Created:** [July 9, 2004, 9:27am UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983 "2004-07-09T09:27:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mx\_guest2004](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mx\_guest2004](https://forum.kirupa.com/u/mx_guest2004)\
**Post date:** [July 9, 2004, 9:27am UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/1 "2004-07-09T09:27:02Z")

</div>

Hi,  
I have an onEnterFrame in frame 1 which contains a function to fade in my MC. My MC fades in.  
I want that my MC fades out in frame 50.  
Do I have to go to frame 50 and put a keyframe and another onEnterFrame in frame 50 ? Or is there a way to control this by AS? I mean saying that myMC.\_currentFrame is 50?

Thanks  
mx-guest2004

---

<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:** [July 9, 2004, 11:36am UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/2 "2004-07-09T11:36:43Z")

</div>

```auto

onClipEvent (enterFrame) {
	if (mc._currentframe == 50) {
		//do what ever
	}
}

```

---

<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:** [July 9, 2004, 11:50am UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/3 "2004-07-09T11:50:29Z")

</div>

Thanks, but I wanted to control the MC from the main timeline and not with event handler.  
frame 1 (of the main movie:root timeline) : fades in  
frame 50 (of the main movie:root timeline) : scales up  
frame 150 (of the main movie:root timeline) : fades out  
Do I have to go to the frames 50 and 150 and put a keyFrame with new onEnterFrame functions?

mx-guest2004

---

<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:** [July 9, 2004, 4:10pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/4 "2004-07-09T16:10:41Z")

</div>

these are good questions!  
I have been looking for this very thing!  
I have a large movie that is made up of tweens and long streches of hundreds of frames,… and i am looking for a way to make it happen with AS.  
I just dont really know what to look for in the forums.  
This is nice.  
it is a small clue.  
I look forward to following this.

-me :tb:

---

<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:** [July 9, 2004, 4:22pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/5 "2004-07-09T16:22:35Z")

</div>

Good silencematters 🙂  
You know, one can use or should use AS instead of tweens. I do much of animations by AS. What I’m looking for, is a method which help me not to put keyFrames manually first on the main timeline and then write AS in each keyFrame which would contain animations etc.  
I hope some AS guru comes to this thread soon :))

mx-guest2004

---

<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:** [July 9, 2004, 4:35pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/6 "2004-07-09T16:35:32Z")

</div>

onClipEvent (enterFrame) {

I have previous director experience,… and for some reason lingo seemed easier to grasp. One thing i noticed,… is that when learning it,. there were things that you were able to grab onto and run with. So with this issue of Animating with AS… is the onClipEvent action the one that we will be using to controll a lot of this? I am sure there are more ways than one to do this,… just looking for some guidance here.

-me :tb:

---

<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:** [July 9, 2004, 4:35pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/7 "2004-07-09T16:35:53Z")

</div>

mx-guest2004:-  
you are right in assuming that you can replace one function for onEnterFrame with another and i have made the file you were asking for.  
[http://www.gifsrus.com/testfile/sample1.fla](http://www.gifsrus.com/testfile/sample1.fla)  
I also like keeping all code together as much as possible.However, the way you are making your file is a little strange. It would be much better to have your main movie all in one frame and animate all the seperate mc`s from that point.  
So for the sample1 file, you could delete all the frames except the first and type this in the actions panel  
mc.\_alpha = 0;  
function fadein() {  
this.\_alpha += 2;  
if (this.\_alpha\>=100) {  
this.onEnterFrame = scaleUp;  
}  
}  
function scaleUp() {  
this.\_xscale = this.\_yscale += 1;  
if (this.\_xscale\>=200) {  
this.onEnterFrame = fadeOut;  
}  
}  
function fadeOut() {  
this.\_alpha -= 2;  
if (this.\_alpha\<=0) {  
delete this.onEnterFrame;  
}  
}  
mc.onEnterFrame =fadein

and it would do the same thing.

---

<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:** [July 9, 2004, 4:55pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/8 "2004-07-09T16:55:30Z")

</div>

Thanks  
Ok, stringy. Your method is the method I use too 🙂  
The only thing is that do we have to go manually to those keyFrames?  
You say " It would be much better to have your main movie all in one frame and animate all the seperate mc`s from that point." .  
Ok, this is what I want to know how. If you want to animate MC at frame number 100, you’re in frame 1 and there is not any frame 100. How can I tell the MC to scale up at frame 100 and fade out at frame 150?  
I don’t want to use loading external movies as my animation is story based and I can’t wait for preloading them …

mx-guest2004

---

<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:** [July 9, 2004, 5:02pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/9 "2004-07-09T17:02:37Z")

</div>

Ok you have edited your post.  
Yes things work on the first frame. What about some delay between first action and second action? Look:  
[AS]  
mc.\_alpha = 0;  
function fadein() {  
this.\_alpha += 2;  
if (this.\_alpha\>=100) {  
this.onEnterFrame = scaleUp;  
}  
}  
DELAY. HOW ???

function scaleUp() {  
this.\_xscale = this.\_yscale += 1;  
if (this.\_xscale\>=200) {  
this.onEnterFrame = fadeOut;  
}  
}  
[/AS]

---

<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:** [July 9, 2004, 5:05pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/10 "2004-07-09T17:05:06Z")

</div>

Yes Stringy! This is something great i can learn from!  
thank you. I also appreciate mx-guest2004’s comment about making the file work from one frame. I would like to see how that happens?

-me :tb:

---

<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:** [July 9, 2004, 5:13pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/11 "2004-07-09T17:13:44Z")

</div>

mc.\_alpha = 0;  
function fadein() {  
this.\_alpha += 2;  
if (this.\_alpha\>=100) {  
delete this.onEnterFrame;  
myInterval = setInterval(wait, 3000);  
}  
}  
function wait() {  
mc.onEnterFrame = scaleUp;  
clearInterval(myInterval);  
}  
function scaleUp() {  
this.\_xscale = this.\_yscale += 1;  
if (this.\_xscale\>=200) {  
this.onEnterFrame = fadeOut;  
}  
}  
function fadeOut() {  
this.\_alpha -= 2;  
if (this.\_alpha\<=0) {  
delete this.onEnterFrame;  
}  
}  
mc.onEnterFrame = fadein;

You can use setInterval to pause and in fact i use it more than enterFrame these days. Need to remember to delete onEnterFrame if not reassigning.  
This pauses for 3 seconds(3000), which you can change.

---

<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:** [July 9, 2004, 5:29pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/12 "2004-07-09T17:29:25Z")

</div>

would you guys mind posting your test file,. after you insert the new code? The Code makes sense,. but i am interested to see how you have set up the frames in the timeline. the combination of the two doent make sense.

Also,… if i were to serch for more information on how to do this? what would be a good query? what is it called?

“moving from Tween to AS”  
“Animate MC with AS”

thank you for the help so far.

-me

---

<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:** [July 9, 2004, 5:56pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/13 "2004-07-09T17:56:48Z")

</div>

> [@silencematters](#):
>
> would you guys mind posting your test file,. after you insert the new code? The Code makes sense,. but i am interested to see how you have set up the frames in the timeline. the combination of the two doent make sense.
> 
> Also,… if i were to serch for more information on how to do this? what would be a good query? what is it called?
> 
> “moving from Tween to AS”  
> “Animate MC with AS”
> 
> thank you for the help so far.
> 
> -me

I have replaced the previous file with a new one.  
This is just basic actionscript, and not even the best way to do something like this. You might look up functions, variables and easing but make sure you get something written for mx rather than flash 5 or you will just get more confused.

---

<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:** [July 9, 2004, 6:14pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/14 "2004-07-09T18:14:03Z")

</div>

hi everyone,  
i’m pretty new to AS but could i use a similar code but replace onclipevent with onrelease button to perform the as tween.

---

<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:** [July 9, 2004, 6:21pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/15 "2004-07-09T18:21:43Z")

</div>

stringy,  
I’ll do some experiments with one frame and wait function. It seems good.  
Thank you very much for helping us here. 🙂

mx-guest2004

---

<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:** [July 9, 2004, 7:13pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/16 "2004-07-09T19:13:21Z")

</div>

> [@Gupps](#):
>
> hi everyone,  
> i’m pretty new to AS but could i use a similar code but replace onclipevent with onrelease button to perform the as tween.

We have not really been talking about code on buttons/mcs but on timelines.  
You can use a button to trigger onEnterFrame to make something move. I have put an example of this on the sample 1 file above.(last few lines)

---

<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:** [July 9, 2004, 7:18pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/17 "2004-07-09T19:18:24Z")

</div>

> [@mx-guest2004](#):
>
> stringy,  
> I’ll do some experiments with one frame and wait function. It seems good.  
> Thank you very much for helping us here. 🙂
> 
> mx-guest2004

Glad to help, but i feel i may have mislead you a little.  
You should not often need to use setInterval to pause something but it is handy at times. Normally you would set up your functions so that when mc1 “did something”, this would trigger something in mc2 etc. Anyway if you have any problems post back here and if you describe what you are trying to do, i`ll try show you how to do it on one frame.

---

<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:** [July 9, 2004, 8:26pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/18 "2004-07-09T20:26:22Z")

</div>

Ok, stringy. Let’s take “real” situation.  
In an animation we have some MCs which may appear after each other.  
For instance Pic1 appears (fades in) and remains there. After that Pic2 fades in and maybe at the same time as Pic2, Pic3 comes from the right side. You see, things may happen in a combination and we have to deal with many different wating functions. Should this method be used for these kind of situations?

mx-guest2004

---

<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:** [July 9, 2004, 8:36pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/19 "2004-07-09T20:36:21Z")

</div>

many thanks stringy. I think i understand now. I can apply this with laco’s tweening animations AS.

---

<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:** [July 9, 2004, 8:54pm UTC](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983/20 "2004-07-09T20:54:48Z")

</div>

> [@mx-guest2004](#):
>
> Ok, stringy. Let’s take “real” situation.  
> In an animation we have some MCs which may appear after each other.  
> For instance Pic1 appears (fades in) and remains there. After that Pic2 fades in and maybe at the same time as Pic2, Pic3 comes from the right side. You see, things may happen in a combination and we have to deal with many different wating functions. Should this method be used for these kind of situations?
> 
> mx-guest2004

yes exactly that  
you can use “if” statements  
eg/this would be inside a function,(pic2fadein() &pic3comein() are 2 other functions)

if(pic1.\_alpha\>=100){  
pic2fadein()  
pic3comein()  
};

[Next page](https://forum.kirupa.com/t/onenterframe-and--currentframe-help-please/56983.md?page=2)
