Groups | Blog | Home
all groups > flash actionscript > january 2007 >

flash actionscript : mc out of scope event handler



heavyp
1/24/2007 9:25:33 PM
TIA,

I have two event handlers on the Main Timeline.(attached at the bottom)
Also on the Main Timeline, there is an outerMC(2frames), which contains, a
innerMC1(frame1) and an innerMC2(frame2).

With the event handler on the Main Timeline, when the nested movieclip is no
longer under the playhead, the event handler goes out of scope and stays out of
scope, even if the playhead is returned to the firstframe, via the simple on()
{prevFrame();} button.

This seems to be very odd, a parent function, does not go out of scope, when
the playhead moves within a nested movieclip.

How can I have centralized event handler code on the Main Timeline and be able
to address nested movieclips regardless if that movieclip exists on the first
frame or not.

code:

outerMC.innerMC1 = function (){ this._parent.nextFrame();}
outerMC.innerMC2 = function (){ this._parent.prevFrame();}
kglad
1/24/2007 10:09:07 PM
you can't.

heavyp
1/24/2007 11:02:18 PM
Thank you for the correction. I also found a small mention in Colin Moock's AS
Flash MX book about the scope and the existance of the object.

So might I use a function call to the Main Timeline, from the frame where the
nested mc exists.
frame1: _root.myFunctionWhichContainsMyEventHandlerMethod1().
frame2: _root.myFunctionWhichContainsMyEventHandlerMethod2().
The code can be centralized and use this, event handler method. It works, but
is there a better way?

The corrected code:

outerMC.innerMC1.onPress = function (){ this._parent.nextFrame();}
outerMC.innerMC2.onPress = function (){ this._parent.prevFrame();}
kglad
1/25/2007 2:42:52 AM
well, there is a better way. and that's to use object oriented programming.

you would create a class the defines all the methods and properties of your
object and then when an member of your class is instantiated (created), your
class definitions would be retrieved.
AddThis Social Bookmark Button