all groups > flash actionscript > august 2005 >
You're in the

flash actionscript

group:

order and number of times AS code executed



Re: order and number of times AS code executed kglad
8/20/2005 9:47:02 PM
flash actionscript: flash does not re-enter the frame of a one frame movieclip and therefore does
not re-execute the code attached to that frame. further if you place a
this.gotoAndStop(this._currentframe) or this.gotoAndPlay(this._currentframe),
the playhead will not re-enter the frame to which that code is attached and
will not re-execute any code in that frame.
order and number of times AS code executed leut
8/20/2005 11:16:22 PM

I am having trouble understanding the order Flash choses to execute code
for what I would think would be a simple case.
Consider the following experiments:

1) Create an application with two frames. Attach AS code to each
frame, say:

Frame 1: trace("inside 1") ;
Frame 2: trace("two") ;

It now happily alternates the traces statements for ever as the movie
starts over after completing frame2.

2) Now, just create an application with one frame and
attach AS code to the frame:

trace("hi") ;

Flash only plays this ONCE in the output window. Shouldn't flash print
"hi" out over and over? Why not? Does it not restart the movie after
completing frame one, and hence play frame 1 again, and again...

3) Trying to figure this out I thought maybe it had something to do
with trace and ctrl-enter versus "publishing" the movie. So I created
a dynamic text box and did the same one frame versus two frame example.
Same behavior.

4) I then tried displaying the time (in seconds) by creating
Date() objects in frames 1 and 2, works great, but if only
one frame exists it prints out the time once and never runs the code
again.

5) I tried the one frame example and created an onEnterFrame event,
sticking the time display code inside the function. Sure enough, it
keeps updating the time, so even though there is only one frame, it
presumably keeps playing that frame over and over and runs the
onEnterFrame code. This seems to me to be at odds with (2) above?!


*** Could someone explain this behavior? What am I missing? Why if I
just have one frame does that frame not get re-executed?

Note, there are no stop() or play() command anyplace, no other
movieClips, super simply just a few lines of AS code inside one or two
frames.

Thanks much,

Scott


--
leut
------------------------------------------------------------------------
leut's Profile: http://www.24help.info/member.php?userid=336
View this thread: http://www.24help.info/showthread.php?t=447130

24help.info - IT Newsgroups @ http://www.24help.info
Re: order and number of times AS code executed leut
8/21/2005 12:00:00 AM

Thank you, yes, that makes sense but still leaves part somehwat
"unclean" to me. From the Flash point of view (if no AS code was
included) it makes sense to play a one frame movie only once because
nothing would change. But, when you add an onEnterFrame event handler
it does play the movie over and over even though it is only one frame.
Did the Macromedia designers decide that if an event handler is added in
the AS that then the movieclip would be repeatedly played? I guess
that makes sense, I just don't like apparent inconsitencies....
although, I guess it is a logical one ....

Thanks,

---Scott


--
leut
------------------------------------------------------------------------
leut's Profile: http://www.24help.info/member.php?userid=336
View this thread: http://www.24help.info/showthread.php?t=447130

24help.info - IT Newsgroups @ http://www.24help.info
Re: order and number of times AS code executed Jeckyl
8/21/2005 12:00:00 AM
[quoted text, click to view]

The script you put on a frame is the code that actually happens when the
frame is entered (ie you have to be in another frame and then go to this
frame for the script on this frame to execute .. if you're already on the
frame, it doesn't execute again, even if you tell it to go to the frame
you're on.

I think someone at MM didn't quite think through the naming conventions to
make sure they made sense ! ;)

Jeckyl

Re: order and number of times AS code executed leut
8/21/2005 12:00:00 AM

Okay, it appears ya'll are saying that onEnterFrame() is simply like
setInterval with the interval time determinded by the movie FPS. But,
I found the following on the web that seems to imply that onEnterFrame
modifies its interval time when/if the movie gets bogged down, perhaps
it adjusts to match the "real frame rate" versus the FPS?
Is onEnterFrame somehow really tied to the actual frame rate? DOES it
get executed once per frame (instead of once per 1/FPS seconds?) And
if
so, does that mean a single frame movie does get played over and over
again
if there is an onEnterFrame in the AS code attached to that frame?
(although
it seems foolish to keep redefining and setting up the onEnterFrame
function
rather than running that code once which is an argument in favor of it
playing
that frame only once.


Check out the following two links:

http://www.kirupa.com/developer/actionscript/setinterval.htm
http://www.kirupa.com/developer/actionscript/setinterval2.htm

One snippet of text from the summary of the first link:


" Summary
So basically what setInterval allows you to do is make a unique
onEnterFrame type of event that occurs in the time period you want, at
the beat you want, and not that based on the frame rate of your movie.
However, there is one very important thing to understand about
setInterval. And that is that setInterval runs independent of frame
time. This means that your interval will occur at its set interval no
matter what the speed of the play head in Flash because setInterval is
run off of actual time periods and will not decrease in speed if Flash
starts to bog down in its own frame calculation. "

Still not 100% satisfied with the apparently conflicting explanations.
Thanks,

---Scott


--
leut
------------------------------------------------------------------------
leut's Profile: http://www.24help.info/member.php?userid=336
View this thread: http://www.24help.info/showthread.php?t=447130

24help.info - IT Newsgroups @ http://www.24help.info
Re: order and number of times AS code executed abeall
8/21/2005 12:55:30 AM
When it comes down to it, I think 'onEnterFrame' is simply misnamed. Perhaps
'onEveryFrame', or really, I don't know what would really describe it...
perhaps this is exactly how it got misnamed :-)

Really it just executes the code block at the framerate of your movie. This
confused me when I first started Flash as well, but it's pretty much just a
simple interval, where the interval is the framerate(30fps means 30 executions
per second, ect.)

It really has little/nothing to do with 'entering a frame'
Re: order and number of times AS code executed abeall
8/21/2005 10:34:23 PM
I wondered about using the word 'interval' - you're right, as I did not mean
interval as in setInterval, but in the primitive sense of the word. It does
directly correspond to the framerate the movie is playing at, and has nothing
to do with setInterval. Gosh, this isn't that complicated. onEnterFrame
executes a block of code once per [framerate playback] of the compiled SWF,
wether it's slower than the authored framerate.

Maybe this will help you understand. Pretend that onEnterFrame creates an
independent MovieClip that has an infinite timeline, and on each frame of the
timeline is a copy of the code you have defined in the onEnterFrame function.
Re: order and number of times AS code executed kglad
8/21/2005 10:36:02 PM
Re: order and number of times AS code executed Jeckyl
8/22/2005 12:00:00 AM
[quoted text, click to view]

No .. y'all is not saying that at all. Wherre did you get that from?

[quoted text, click to view]

EXACTLY .. it runs at the real frame rate. There's no a 'but'.

[quoted text, click to view]

Yes .. every time Flash is ready to update the display next (which is
nominally at the frame rate you specify, but may be slower if something is
'bogging it down'), the onEnterFrame event executes. It is not tied to a
particular interval of time (like setInterval) and it is not dependant on
the movie going from one frame to the another (like script in a frame)

[quoted text, click to view]

No .. why would it mean that? You're talking about completely different
things. A single frame movie goes into one frame and doesn't move from it.
Its like walking into a room with no exits .. you wouldn't say you are
walking into the room over and over again, just that you walk into it once
and stay there. The script in the frame is like having something happen
when you walk through the door into a room. Unless you go out and come back
in, it won't execute again. This is unrelated to the onEnterFrame which
relates to when Flash Player updates its display. And unrelated to
setInterval that runs from a timer (or though no exactly .. it can get quite
a bit out)

[quoted text, click to view]

onEnterFrame is NOT attached to a frame. Have you not understood what was
said?

[quoted text, click to view]

I don't know what you're talking about here? What argument? What exactly
is it you WANT to do?

[quoted text, click to view]

Nothing is conflicting .. where is the conflict .. it seems you simply don't
"Get it" yet.

Jeckyl

Re: order and number of times AS code executed leut
8/22/2005 12:00:00 AM

Okay, I guess that makes sense. It is identical to setInterval, except
the interval time dynamic adjusts to the current best estimate of the
movie frame rate.

The "conflicting info" was that it is seperate from the actual playing
of franes (like setInterval) rate in the web page I quoted implies that
the onEnterFrame interval IS affected by the actual frame rate.

I think it is all clear in my head now.
Sometimes it is these little things that drive me insane.


Thanks to you all, regards,

---Scott


--
leut
------------------------------------------------------------------------
leut's Profile: http://www.24help.info/member.php?userid=336
View this thread: http://www.24help.info/showthread.php?t=447130

24help.info - IT Newsgroups @ http://www.24help.info
AddThis Social Bookmark Button