|
Another helper class - liaison - used to call get/set methods and properties
package classes
{
import flash.display.*;
/*
This class just helps us do things we could do manually.
It aids in calling get and set methods and variables that have been setup in a child swf.
It will be used in the Parent Child Control example.
*/
public class liaison
{
private var baby:*;
public function liaison(s:*)
{
/* s should be the child DisplayObjectContainer instance */
baby = s;
}
public function invoke(property:String, ... args):void
{
if (baby) {
if (baby.hasOwnProperty(property))
{
if (args.length >= 1){
baby[property].apply(null, args);}
else{
baby[property].apply(null);}
}
}
/* manually we can also say:
childInstance["methodGetterName"].apply(null, [args as an Array]);
in the parent. */
}
public function setP(prop:String, toThis:*):void
{
if (baby) {
if (baby.hasOwnProperty(prop))
{
baby[prop] = toThis;
}
}
/* manually we can also say:
childInstance["childSetterProperty"] = someValue;
in the parent. */
}
public function getP(prop:String, defaulter:* = null):*
{
if (baby) {
if (baby.hasOwnProperty(prop))
{
defaulter = baby[prop];
}
}
return defaulter;
/* manually we can also say:
var fromChild:* = childInstance["childGetterProperty"];
in the parent. */
}
}
}
|