canvas1.myVariable = "some value" canvas1.myFunction() (provided myVariable and myFunction are declared public)
Doesn't matter if they are inside accordian or any other container (except for the creationPolicy gotcha). On Thu, Feb 28, 2008 at 5:14 PM, honoraryvato <[EMAIL PROTECTED]> wrote: > This works using your code but what is the Canvas is a custom > component that extends Canvas? Meaning the accorion code looks like > > <mx:Accordion creationPolicy="all" id="accordionBar"> > <ns1:MyCanvas id="canvas1" /> > </mx:Accordion> > > How would I get this to work? > > --- In [email protected] <flexcomponents%40yahoogroups.com>, > "Beau Scott" <[EMAIL PROTECTED]> > wrote: > > > > > Be careful with this though because the accordion's children will not be > > fully initialized until they're displayed for the first time. So > accessing > > children of the accordion's child components will not be possible. > You can > > get around this by setting the accordion's creation policy to "all", > though > > this will increase rendering time memory usage as you'll be initializing > > components that you may never need. > > > > > > > > Example: > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="vertical" > > creationComplete="onCreationComplete(event)"> > > > > <mx:Script> > > > > <![CDATA[ > > > > protected function onCreationComplete(event:Event) > : void > > > > { > > > > trace(lbl2.text); > > > > } > > > > ]]> > > > > </mx:Script> > > > > <mx:Accordion> > > > > <mx:Canvas id="can1"> > > > > <mx:Label id="lbl1" text="lbl1"/> > > > > </mx:Canvas> > > > > <mx:Canvas id="can2"> > > > > <mx:Label id="lbl2" text="lbl2"/> > > > > </mx:Canvas> > > > > <mx:Canvas id="can3"> > > > > <mx:Label id="lbl3" text="lbl3"/> > > > > </mx:Canvas> > > > > </mx:Accordion> > > > > </mx:Application > > > > > > > > Running this will result in a null pointer exception because lbl2 hasn't > > been created. > > > > > > > > However, by altering the creationPolicy to all, it will work just fine: > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="vertical" > > creationComplete="onCreationComplete(event)"> > > > > <mx:Script> > > > > <![CDATA[ > > > > protected function onCreationComplete(event:Event) > : void > > > > { > > > > trace(lbl2.text); > > > > } > > > > ]]> > > > > </mx:Script> > > > > <mx:Accordion creationPolicy="all"> > > > > <mx:Canvas id="can1"> > > > > <mx:Label id="lbl1" text="lbl1"/> > > > > </mx:Canvas> > > > > <mx:Canvas id="can2"> > > > > <mx:Label id="lbl2" text="lbl2"/> > > > > </mx:Canvas> > > > > <mx:Canvas id="can3"> > > > > <mx:Label id="lbl3" text="lbl3"/> > > > > </mx:Canvas> > > > > </mx:Accordion> > > > > </mx:Application> > > > > > > > > > > > > Beau > > > > > > > > From: [email protected] <flexcomponents%40yahoogroups.com> > [mailto:[email protected] <flexcomponents%40yahoogroups.com>] > > On Behalf Of Erik Price > > Sent: Thursday, February 28, 2008 2:39 PM > > To: [email protected] <flexcomponents%40yahoogroups.com> > > Subject: Re: [flexcomponents] Set variable and call method in Canvas of > > Accordion > > > > > > > > On Thu, Feb 28, 2008 at 1:57 PM, honoraryvato <HYPERLINK > > "mailto:honoraryvato%40yahoo.com"[EMAIL PROTECTED]> wrote: > > > > > I have an Accordion. In the accordion I have custom components. Those > > > components extend the Canvas class. From the application stage, how > > > can I set variables inside one of the Canvas views of the Accordion? > > > Also, how can I call a function in one of the Canvas views? > > > > Give the Canvas views MXML IDs, and then you can simply refer to them > > as properties of the Accordion by that ID. > > > > MyAccordion.mxml: > > > > <mx:Accordion> > > <MyCanvas id="foo" /> > > </mx:Accordion> > > > > Application.mxml: > > > > <mx:Application creationComplete="handleCreationComplete()"> > > <mx:Script> > > private function handleCreationComplete():void > > { > > bar.foo.someVariable = "frank"; > > bar.foo.someFunction(); > > } > > </mx:Script> > > > > <MyAccordion id="bar" /> > > </mx:Application> > > > > e > > > > > > > > > > > > No virus found in this incoming message. > > Checked by AVG Free Edition. > > Version: 7.5.516 / Virus Database: 269.21.1/1303 - Release Date: > 2/28/2008 > > 12:14 PM > > > > > > No virus found in this outgoing message. > > Checked by AVG Free Edition. > > Version: 7.5.516 / Virus Database: 269.21.1/1303 - Release Date: > 2/28/2008 > > 12:14 PM > > > > >
