4 Replies Latest reply on Sep 12, 2006 11:14 AM by dishmael

    Re-Initialize Panel

    dishmael Level 1
      I have several views, one of which is a Panel that displays data from a web service. I'd like to have that data refreshed every time the Panel is viewed. I imagine I need to add a handler to one of the Panel events so that each time the Panel is viewed it refreshs its data. I tried using creationComplete() and initialize() but those are only fired once. Does anyone know which event I should use?
        • 1. Re: Re-Initialize Panel
          Level 1
          What do you mean by saying you "have several views"? How are these displayed?


          Are you using a ViewStack object for these views? If so, the "show" event is triggered when an object's state is changed from invisible to visible in the viewstack, maybe that would help?

          --Andy
          • 2. Re: Re-Initialize Panel
            dishmael Level 1
            Sorry, I should've been more succinct in my question. I have several states (views) that display custom components. One of those is a custom component based on the Panel component. When I switch from one state (view) to another, I'm trying to figure out what event gets fired every time that state (view) is shown.

            For example, I have something like this in my base state:

            <mx:states>
            <mx:State name="MainView">
            <mx:RemoveChild target="{loginBox}" />
            <mx:AddChild position="lastChild">
            <wcg:MainMenu left="10" top="10" right="10" itemClick="menuHandler(event);"/>
            </mx:AddChild>
            <mx:AddChild position="lastChild">
            <wcg:MainPanel id="mainPanel" left="10" top="40" right="10" bottom="10"/>
            </mx:AddChild>
            </mx:State>
            <mx:State name="AccountView">
            <mx:RemoveChild target="{loginBox}" />
            <mx:AddChild position="lastChild">
            <wcg:MainMenu left="10" top="10" right="10" itemClick="menuHandler(event);"/>
            </mx:AddChild>
            <mx:AddChild position="lastChild">
            <wcg:AccountPanel id="acctPanel" left="10" top="40" right="10" bottom="10"/>
            </mx:AddChild>
            </mx:State>
            </mx:states>

            When I switch from MainView to AccountView, I want some code to execute in the AccountView; specifically, I want to go fetch new data from a web service. I've created an init() function to do that:

            public function init():void {
            service.getList.send();
            }

            However, I can't seem to figure out what event gets fired when a state is selected. I've tried creationComplete() and initialize() but those only get called once when the custom component (AccountPanel) gets called.

            So my questions is, what event should I create a handler for that fires when a state is changed? Right now I'm doing that programmatically in the base state whenever the AccountView is selected. Perhaps thats the best solution, but it doesn't seem very clean.
            • 3. Re: Re-Initialize Panel
              inlineblue Level 1
              The State object itself dispatches the events enterState and exitState. ie:

              <mx:State name="MainView" enterState="...">
              • 4. Re: Re-Initialize Panel
                dishmael Level 1
                That worked perfectly, thanks!