Hi Ben,

 

I personally do not like circular dependencies. In your case the ViewStack would know about its children and the children also know about the ViewStack. If you later decide to hang your children in a different container you will probably have to rewrite some code in the children. It’s a tight integration.

 

To communicate ‘downwards’ (from ViewStack to children) I use interfaces, which actually means that I can call the methods of the children directly from the ViewStack.

 

To communicate ‘upwards’ (from the child to a ‘container’ which could be the ViewStack) I use event handling. So, the container registers himself as listener for a child custom event; once the child encounters a situation where it wishes to communicate with the container, it fires the event and the container catches it.

 

HTH,

Franck

 


From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of ben.clinkinbeard
Sent: Saturday, August 12, 2006 5:03 AM
To: [email protected]
Subject: [flexcoders] Best way to reference items in a parent MXML component?

 

I have a ViewStack whose child elements each contain a graph. I would
like to define some things in the file that holds the ViewStack so
that all of the child charts can use them, but am not sure of the best
way to reference and call these things. Ideally I would like to
somehow pass in a reference to the containing object so that I don't
have to pass several items into each child, but have yet to figure out
a way to do that. I know there has to be a better way than what I have
now:

// App.mxml
<mx:Script>
<![CDATA[
protected function woot():void
{
trace("called");
}
]]>
</mx:Script>
<mx:ViewStack id="vs">
<one:OneChild f="woot" />
<two:TwoChild f="woot" />
</mx:ViewStack>

// OneChild.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
public var f:Function;
]]>
</mx:Script>
<mx:Button label="One Child" click="f.call(this);"/>
</mx:Canvas>

Any help is greatly appreciated.

Thanks,
Ben

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





YAHOO! GROUPS LINKS




__,_._,___

Reply via email to