Topic: Will onEnterFrame slow down flash?

I use a lot of onEnterFrame in Flash. An example is:

mc.onEnterFrame = function() {

this._alpha += (100 - this._alpha)/3

}


When that has reached "full" alpha, does it stop or will it just continue and drain Flash from power?

Re: Will onEnterFrame slow down flash?

I believe it will actually keep going, or at least keep setting the value to 100, can't remember which, exactly...

How about this?

mc.onEnterFrame = function() {
  if(this._alpha < 100) { 
    this._alpha += (100 - this._alpha)/3
  }
}

Re: Will onEnterFrame slow down flash?

Kelli wrote:

I believe it will actually keep going, or at least keep setting the value to 100, can't remember which, exactly...

How about this?

mc.onEnterFrame = function() {
  if(this._alpha < 100) { 
    this._alpha += (100 - this._alpha)/3
  }
}

Yes. That is the answer. But will it ever reach 100?

Re: Will onEnterFrame slow down flash?

This would probably do it. It will delete your onEnterFrame once its done and also snap it to 100 if its real close. (didn't actually test it though, so I hope you will smile )

mc.onEnterFrame = function() {
    if (this._alpha<100) {
        if(100 - this._alpha <1){
            this._alpha = 100;
            delete onEnterFrame;
        }else{
            this._alpha += (100-this._alpha)/3;
        }
    }else{
        delete onEnterFrame;
    }
};

Re: Will onEnterFrame slow down flash?

ordinathorreur wrote:

This would probably do it. It will delete your onEnterFrame once its done and also snap it to 100 if its real close. (didn't actually test it though, so I hope you will smile )

mc.onEnterFrame = function() {
    if (this._alpha<100) {
        if(100 - this._alpha <1){
            this._alpha = 100;
            delete onEnterFrame;
        }else{
            this._alpha += (100-this._alpha)/3;
        }
    }else{
        delete onEnterFrame;
    }
};

Thanks ordinathorreur. I actually did something similar, but I didn't know about delete onEnterFrame, even thought I suspected there must be such a possibility. Good to know. smile

Re: Will onEnterFrame slow down flash?

Hi,

To add to the code posted above, to know when an onEnterFrame event is being called, simply add trace() methods throughout your code. (I've also removed some of the extraneous code.) Like so:

mc.onEnterFrame = function() {
    trace(">> onEnterFrame()");
    if (this._alpha >= 99.5){
        this._alpha=100;
        trace(">> onEnterFrame() removed");
        delete onEnterFrame;
    } else{
        this._alpha += (100-this._alpha)/3;
        trace(">> _alpha: " + this._alpha);
    }
};

When you test your movie in Flash, every time the trace() method is called it will display a string in the Output window. This script will trace() ">> onEnterFrame()" every time a new frame is entered. It will also output the current alpha value of your movieclip (such as ">> _alpha: 39").

Once the _alpha value has reached or exceeded 99.5 the onEnterFrame() method will be removed with a trace() method saying ">> onEnterFrame() removed". From then on you should not see any more ">> onEnterFrame()" messages in the Output window.

This is a very handy way to develop. You know what Flash is doing every step of the way. No second guesses. Once you know your code is doing what you want it to do, just comment out the trace methods using "//". This way you won't have too much going on in the Output window.

Cheers.

Re: Will onEnterFrame slow down flash?

If you are spending a lot of your development time creating simple tweens I would suggest downloading Fuse. This will allow you to create beautiful tweens quickly and allow you to spend your time developing the important stuff.

On the other hand, if you are busy learning and having fun with Flash, go nuts.