onEnterFrame() and _currentFrame, help please

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


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

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

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:

Good silencematters :slight_smile:
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

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:

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
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.

Thanks
Ok, stringy. Your method is the method I use too :slight_smile:
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

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]

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:

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.

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.

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.

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

mx-guest2004

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)

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.

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

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

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()
};