PDA

View Full Version : Is good practice to call parent functions in this way ?



aneuryzma
January 18th, 2009, 02:23 AM
is good to call parent functions from the child ?

Ex.

MovieClip(parent).myTimer.start();


thanks

Krilnon
January 18th, 2009, 02:40 AM
That depends on who you ask, but I'm guessing that most people here would say that it isn't a good practice to do that.

aneuryzma
January 18th, 2009, 02:48 AM
oh ok. So what's a good practice ?
to use an object oriented approach ? and call class instance functions ?

thanks

Felixz
January 18th, 2009, 02:55 AM
Well, it isn't because you are typecasting to dynamic MovieClip class, and when you chnge the parent or rename the timer reference, you won't get an error.
Were are some oop tips... http://www.kirupa.com/forum/showthread.php?p=2167721#post2167721

aneuryzma
January 18th, 2009, 02:59 AM
oh ok.

One last question: if I create the object from UI, instead of using actionscript, how can I create then an object for the reference ?

is it possible ? or should I always start from actionscript if I want then to refer to it ?

PS. To use the UI makes the positioning much easier... for the layout of my project...

.ral:cr
January 18th, 2009, 03:42 AM
you acces the object by its instance name, see the properties window.

aneuryzma
January 18th, 2009, 03:50 AM
ok, and if I have a Timer in the parent MovieCilp, how can I refer to it ?

Should i use the Timer name in the parent movieclip ? Is it visible from the child ?

.ral:cr
January 18th, 2009, 04:03 AM
no, only visual objects can be dragged into scene and have an instance name

in case of timer depends why you want it to be on parent, i may say that is already badly designed if you need this.
if you're not working OOP it's better to keep all the code in one place.

aneuryzma
January 18th, 2009, 04:10 AM
ok.

I need to trigger the timer when the child movieClip is ended.

So I call the myTimer.start() method from the child movieClip.

Should I use a listener in the parent to detect the end of the child movieclip instead ?

How could I implement it ?

thanks

Raziel
January 19th, 2009, 10:20 AM
dispatchEvent(new Event("finished", true));

parent.addEventListener("finished", doSomething);