flash - Referencing back to the parent from a child object -


my question pertaining best practice accessing child object's parent. let's class instantiates class, class instance referenced object. child object, best way reference parent object? know of couple ways use often, i'm not sure if a) there better way or b) of them better practice

the first method use getdefinitionbyname, not instantiate class, allow access inside of publicly declared.

_class:class = getdefinitionbyname("com.site.class") class; 

and reference variable based on parent child hierarchy.
example, if child attempting reference class that's 2 levels itself:

_class(parent.parent).function(); 

this seems work fine, required know level @ child @ compared level of parent attempting access.

i can following statement trace out [object classname] flash's output.

trace(class); 

i'm not 100% on implementation of line, haven't persued way reference object outside of current object i'm in.

another method i've seen used pass reference class object creating , catch constructor argument

var class:class = new class(this);   

and in class file

public function class(objectref:object) {     _parentref = objectref; }  

that reference requires step using child parent hierarchy though.

i import class, , use direct filepath reference method inside of class, regardless of parent or not.

import com.site.class; com.site.class.method(); 

of course there parent child relationship irrelevant because i'm accessing method or property directly through imported class.

i feel i'm missing obvious here. i'm looking confirmation if these correct ways reference parent, , if ideal, or over-looking else?

it's have class it's own instance , reduce tight coupling else (as in case, it's parent). if parent.dosomething() it's not possible use class in container doesn't have dosometing() method. think it's better pass in whatever class may need , inside class doesn't have parent.parent etc anymore.

with if in future want change structure, it's easy pass in new reference; implementation of child class doesn't have change @ all.

the third alternative have here different, it's accessing class level static method (you don't have type whole class path when accessing method), not instance method in first two.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -