Thanks Tim. I initially tried using the "show" event on the
component's canvas but it never got invoked. Then I realized that I
had a canvas in the view stack that included my component:
<mx:ViewStack>
<mx:Canvas id="myComponent1">
<view:MyComponent/>
</mx:Canvas>
<mx:Canvas id="myComponent2">
<view:MyComponent/>
</mx:Canvas>
<mx:Canvas id="myComponent3">
<view:MyComponent/>
</mx:Canvas>
<mx:Canvas id="myComponent4">
<view:MyComponent/>
</mx:Canvas>
</mx:ViewStack>
<view:MyComponent>
<mx:Script>
<![CDATA[
private function myShowMethod1():void {
}
private function myShowMethod2():void {
}
]]>
</mx:Script>
<mx:ViewStack>
<mx:Canvas id="myCanvas2" show="myShowMethod1()">
<view:MyView1/>
</mx:Canvas>
<mx:Canvas id="myCanvas2" show="myShowMethod2()">
<view:MyView2/>
</mx:Canvas>
</mx:ViewStack>
</view:MyComponent>
I was expecting the myShowMethod1() and myShowMethod2() to be invoked
when the view:MyComponent was brought into view and this was not the case.
I ended up hooking the show event in "myComponent1" and had this
invoke a method in view:MyComponent and this worked.
Is there a way to make sure the "show" gets invoked on my component?
The problem is solved for now though just does not feel like the right
way.
Thanks.
--- In [email protected], "Tim Walling" <[EMAIL PROTECTED]> wrote:
>
> You could try setting up a show event listener to trigger your
> initialization code. Something like this:
>
> <mx:ViewStack>
> <mx:Canvas show="handleShowEvent()"/>
> </mx:ViewStack>
>
>
> Whenever the ViewStack makes the canvas the visible/active one, the show
> event would fire.
>
> or if your Canvas is an mxml component, it could handle the show event
> internally:
>
> <mx:ViewStack>
> <view:MyCanvas/>
> </mx:ViewStack>
>
> MyCanvas.mxml
> <mx:Canvas show="handleShowEvent()">
> <mx:Script>
> private function handleShowEvent(event:FlexEvent):void
> {
> // call initialize code
> }
> </mx:Script>
> </mx:Canvas>
>
> Then each of your components in the ViewStack would manage their
respective
> show events.
>
>
> Tim
>
>
> On 23 Mar 2007 17:02:56 -0700, wdsnapper <[EMAIL PROTECTED]> wrote:
> >
> > I am using a ViewStack to contain a set of Canvas'. I switch between
> > items in the stack by clicking on buttons. I want to be able to
> > detect when a Canvas gains focus and run a method to initialize
> > content on that Canvas.
> >
> > What is the correct event to monitor to achieve this behavior?
> >
> > Thanks in advance.
> >
> >
> >
>
>
>
> --
> Tim
> timwalling.com
>