Groups | Blog | Home
all groups > flash actionscript > august 2005 >

flash actionscript : Firing frame action when backing into frames


billrm1
8/12/2005 9:32:40 PM
When I place an object on the stage within a group of frames that are not
separated by keyframes, it is shared across those frames. When I place action
script in a frame across a group of frames, I can see that action script in the
script window no matter which frame has focus. However, it appears that during
play back the action script only fires when the play head is in the frame where
the action script was placed.

In my application I have a group of frames that need to call a function. The
funtion is placed on the first frame in that group. If I come into that group
of frames from the front the function fires correctly. If I pass that group of
frames and come into the last frame in the group where the function is called,
it doesn't fire.

example: the funtion call is placed in frame 5 and can be seen thru frame 10.
When the play head advances from frame 4 to 5 the function fires. However, if
the playhead is in frame 11 and the user moves back to frame 10, the funtion
does not fire.

Anyone know why this is, or better yet the best way to deal with this?

TIA
kglad
8/13/2005 12:22:12 AM
your function must be defined BEFORE it is called. to remedy, place your
function defintion in your movies first frame before any goto statements
directing the playhead to exit frame 1. then you know your function will be
defined before it is called.
billrm1
8/15/2005 12:00:00 AM
Sorry for the poor description of the problem. It is not a problem with getting
my functions to fire, they fire fine. The problem can be demonstrated with any
frame attached action script.

If action script is attached to a group of frames, it only fires on the first
frame even though it can be seen on all the frames in that group. So if you go
past that group of frames and then return any frame but the first in the group,
the script doesn't fire. If you return to the first frame in that group, it
does fire. Because the action script is visible in all the frames, I would
expect it fire on all of them.

Example: Build a 3 frame movie, put a keyframe in the 3rd frame. Put a trace
action in the first frame such as "trace ("frame 1 & 2");". You will be able to
see it in both frames in the scripting window. Put a "stop()" and trace in the
3rd frame saying it is frame 3. On the stage at the 3rd frame put a button with
"gotoAndPlay(1)" and another button with "gotoAndPlay(2)". When you initially
play the movie you will see both sets of traces displayed in output. When you
use the "gotoAndPlay(1)" button both sets of trace will be displayed. However,
with the "gotoAndPlay(2)" the first set of traces is not played just the frame
3 trace.

Thank you.
kglad
8/16/2005 1:48:44 AM
your expectation is not in line with reality. actionscript is attached to a
particular frame (or object) and, by design, only executes when that frame is
entered. even if you're in a frame and execute a gotoAndStop() directing the
playhead to the same frame, all actionscript in that frame will fail to execute
because the playhead does not re-enter a frame in which it currently resides.
the later situation requires a work-around (usually a
gotoAndPlay(this._currentframe-1) with a stop() in the this._currentframe).
however, i can think of no other limitation this imposes.

a situation in line with your expectations would be a huge problem. image
your code in frame 1 executing repeatedly as the playhead moved to frames 2
through N because there were no keyframe between 1 and N.
AddThis Social Bookmark Button