2 Replies Latest reply on Jan 7, 2009 11:05 AM by Mainmanian

    change of state

    Mainmanian Level 1
      I have a main application that entered into state A after a login process. The user then clicked a button that took him to state B. That state has a component C that includes nothing other than simple form and within the form is a submit button. Once the submit button is clicked, a handler is called which updates a DB. Upon return from the DB, I want to get the user back to State B or some other state at the same hierarchy level.

      I have tried to change the state by calling this.currentState = "stateB" and that failed. I could not also not change it to stateA. It gives me an unrecognized state error.

      Need help please! Thanks
        • 1. Re: change of state
          ntsiii Level 3
          Sounds like a scope problem. The code that changes the state must be in the same scope as the states themselves.

          Create a function the does that state change, test it, then call it from the result handler.

          Be sure you understand what "this" means in your particular context.

          Tracy
          • 2. Re: change of state
            Mainmanian Level 1
            Hi Tracy, thank you for your rapid response. I also think it is a scope issue and I am sure I am doing something silly here. I guess, I am not sure what I am doing wrong including perhaps the understanding of the context of "this". Below is two code snippets; teh first one is where the state "scheduleCourse" is defined and as you can see it has a component"ScheduleCourses". The second code is a part of the ScheduledCourses component code where in the handler, I am trying to change the state to another state "loadCourse" that is of the same hierarchy as scheduleCourse.; Thanks

            Snippet 1
            <mx:State name="scheduleCourse" basedOn="loginSuccess">
            <mx:RemoveChild target="{linkbutton1}"/>
            <mx:RemoveChild target="{button1}"/>
            <mx:SetProperty target="{image1}" name="x" value="15"/>
            <mx:SetStyle target="{tabnavigator1}" name="horizontalCenter" value="-47"/>
            <mx:AddChild relativeTo="{teachCanvas}" position="lastChild">
            <ns1:ScheduleCourses x="26" y="10" height="437" user_id="{user_id}">
            </ns1:ScheduleCourses>
            </mx:AddChild>
            </mx:State>
            <mx:State name="loadCourse" basedOn="loginSuccess">
            <mx:RemoveChild target="{searchCourses}"/>
            <mx:AddChild relativeTo="{canvas3}" position="lastChild">
            <ns1:CourseBrowser user_id="{user_id}" horizontalCenter="0" verticalCenter="0" height="80%" id="coursebrowser1" width="98%">
            </ns1:CourseBrowser>
            </mx:AddChild>
            </mx:State>


            Snippet 2

            private function courseScheduledHandler(event:ResultEvent):void{
            //var scheduledCourseEventObj:Event = new Event("scheduledCourseEvent");
            //dispatchEvent(scheduledCourseEventObj);
            this.currentState="teachCourse";
            }