PDA

View Full Version : onEnterFrame inquiry


winfreebot
01-25-2006, 01:43 PM
Hey guys,

I have two methods that I thought would be infinitely called (since both called onEnterFrame) until deleted and each appears below.

Is there a difference between calling methods in a _root.onEnterFrame = function() and calling them using instanceName.onEnterFrame = methodName;?

Because the updateImage() method turns off when I leave the frame and the other seems to require deletion to turn off. However, I'd like updateImage() to run forever...do I just need to swap how they are called or should they be running similarly already?

//---------------onEnterFrame------------------------------------//
_root.onEnterFrame = function()
{
trace("updateImage()");

photoFrame1.updateImage();

};
//-----------------------------------------------------------------//


//-------------------lights----------------------------------------//
showLamp = function()
{
lamp_start_x = 477;
lamp_start_y = 174;

l = attachMovie("LampPost", "lamppost", 10);
l._x = lamp_start_x;
l._y = lamp_start_y;
l.onEnterFrame = flicker;
};

cancerinform
01-25-2006, 02:03 PM
You can call onEnterFrame for each timeline only once. With timeline I mean movieclip including _root and there should be no difference wheather you have _root or a movieclip. If you want to be sure that more than one onEnterFrame is functional either put several instances of an empty movieclip on stage with different names and refer onEnterFrame to that or use setInterval.

winfreebot
01-25-2006, 02:19 PM
Thanks cancerinform for your help.

I'm not sure though what you mean by "You can call onEnterFrame for each timeline only once." Are you saying that onEnterFrame can only be used once? I thought I only had 1 timeline.

Also, why would empty movie clips act differently?

cancerinform
01-25-2006, 02:57 PM
If you call _root.onEnterFrame at different points in your script more than once, it will be executed only for one function:
_root.onEnterFrame = function () {
trace ("hello");
};
_root.onEnterFrame = function () {
trace ("world");
};


in this case only world will be continously traced.

winfreebot
01-25-2006, 03:04 PM
I thought it over and I think I understand...

you're saying there are multiple timelines...including one for _root as well as timelines for each movieclip. So that's why you're recommending some empty movie clips, so that I can use them for their 1-time-only onEnterFrame?

Did I nail it?

Except I still don't understand why the code below would terminate without me deleting the method from onEnterFrame. It stop being called when I exited the frame.

_root.onEnterFrame = function()
{
trace("updateImage()");

photoFrame1.updateImage();

};

is it at all because of how I created photoFrame (shown below)?

attachMovie("SlideshowFrame", "photoFramei" + (i+1), i, {_x:xPos, _y:yPos});

Thanks again.

cancerinform
01-25-2006, 03:07 PM
Yeah, correct. It works very well.

I don't know the answer to your code question unless I see the whole thing and can test it. Appears to me that this is only part of the code.

Or may be attach fla.

winfreebot
01-25-2006, 03:13 PM
Yes! I understand even more now! I'm getting smarter by the minute, cancerinform!

Thanks for your help.

It turns out, stop me if this isn't it, that my OnEnterFrame method was terminating when a certain "lightenTable" method was called. I checked my lightenTable() method and inside was a

this.onEnterFrame = function()
{ bla bla ba }

that was running. And that's using the _root timeline, so it stopped my first method. Is that right? I think so, because when I turned off lightenTable(), my updateImage() continued running.

God, I wish I had known all this mumbo jumbo sooner. Thanks again.

cancerinform
01-25-2006, 03:23 PM
Probably this referred to _root and would cancel out the first onEnterFrame.