16 Replies Latest reply on Nov 1, 2006 6:57 AM by peterent

    Model Problem

    ForsakenBlade
      The model variable just doesn't change value. I'm trying to get loginCheck to change once the httpservice request is sent then display the new one but it only shows [class int] at all times even when first displayed.

      [Bindable]
      public var loginStatus:Object={
      status:{
      loginCheck:int
      }
      }


      public function loginHandler(event:ResultEvent):void {
      loginData = event.result.Character.CharacterInfo;

      loginStatus.status.loginCheck.int = event.result.Status.loggedIn;
      }

      But this seems to work but then it doesnt transfer to the main app just to the login component.
      [Bindable]
      public var loginStatus:int=0;


      public function loginHandler(event:ResultEvent):void {
      loginData = event.result.Character.CharacterInfo;

      loginStatus = event.result.Status.loggedIn;
      }
        • 1. Re: Model Problem
          ForsakenBlade Level 1
          I really need help with this, I've been trying for quite some time now.

          Even if i set the loginStatus.status.loginCheck = 0

          it still doesnt change I do not know what I am doing wrong am I using models wrong because in the help file thts how it shows me to use them.
          • 2. Re: Model Problem
            peterent Level 2
            [Bindable] refers to the variable immediately declared after the statement. So you have:

            [Bindable]
            public var loginStatus:Object = {status:{loginCheck:int}};

            Which means that changes are being observed on the contents of loginStatus - not on any of its children. Should have done at some point: loginStatus = { something else };

            The a change event would have fired; you just changed a member of a member of loginStatus, you didn't change loginStatus itself.

            Since you are creating a complex structure, it would be better (IMHO) to create a LoginStatus class with its own bindable members.
            • 3. Model Problem
              ForsakenBlade Level 1
              even with what you have given me only the component has it change but in the main.mxml file it never changes thats the problem I am facing and I can't figure out how to do it.
              • 4. Re: Model Problem
                peterent Level 2
                I guess I really misunderstood. I've read and re-read your entries several times now. You wrote in your first entry:

                loginStatus.status.loginCheck .int = event.result.Status.loggedIn;

                The .int doesn't make any sense - was that a typo? The int is the datatype; what you did there was create a new field/property of loginCheck called int and assign it to whatever event.result.Status.loggedIn is. So I'm assuming you just have a typo.

                In your section entry you wrote "Even if i set the loginStatus.status.loginCheck = 0 it still doesn't change" - what doesn't change - that's the part I'm confused about. What do you mean when you say it "doesn't transfer to the main app" ? Are you using data binding with it and if so, how?
                • 5. Model Problem
                  ForsakenBlade Level 1
                  okay lets see if i can get this clear im really bad at explaining lol sorry.

                  I have
                  main.mxml (the defualt application)
                  environment.mxml (custom component)
                  login.mxml (custom component)
                  functions.as

                  in the main.mxml I have

                  <mx:Script source="functions.as"/>

                  <mx:Label text="Label: {loginStatus.loginCheck}"/> // checks loginstatus variable it doesnt change here
                  <mx:ViewStack selectedIndex="{loginStatus.loginCheck}" width="100%" x="0" y="0">
                  <local:login/>
                  <local:environment/>
                  </mx:ViewStack>

                  in the login.mxml i have
                  <?xml version="1.0" encoding="utf-8"?>

                  <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml">
                  <mx:Script source="functions.as"/>

                  <mx:Script>
                  <![CDATA[
                  import mx.events.ValidationResultEvent;
                  import mx.controls.Alert;

                  private function validateLogin():void {
                  var validUserEvent:ValidationResultEvent =
                  accountValidator.validate();
                  var validPasswordEvent:ValidationResultEvent =
                  passwordValidator.validate();

                  if(validUserEvent.type == ValidationResultEvent.VALID && validPasswordEvent.type == ValidationResultEvent.VALID) {
                  sendLogin.send();
                  }
                  }
                  ]]>
                  </mx:Script>

                  <mx:HTTPService id="sendLogin" url=" http://www.chimeraonlinerpg.com/CO/XML/login.php" result="loginHandler(event)" useProxy="false" method="POST">
                  <mx:request xmlns="">
                  <account>{accountInput.text}</account>
                  <password>{passwordInput.text}</password>
                  </mx:request>
                  </mx:HTTPService>

                  <mx:Label text="Check: {loginStatus.loginCheck}" x="10" y="62"/> // checks login status variable it changes here
                  <mx:StringValidator id="accountValidator" source="{accountInput}" property="text" maxLength="15" minLength="5" triggerEvent="help" tooLongError="Account name may not contain more then 15 alphanumeric characters." tooShortError="Account name may not contain less then 5 alphanumeric characters."/>
                  <mx:StringValidator id="passwordValidator" source="{passwordInput}" property="text" maxLength="15" minLength="5" triggerEvent="" tooLongError="Password may not contain more then 15 alphanumeric characters." tooShortError="Password may not contain less then 5 alphanumeric characters."/>

                  <mx:DataGrid dataProvider="{loginData}" x="227" y="10"/>

                  <mx:Form width="465" height="254" y="188" x="149">

                  <mx:Panel width="100%" height="200" layout="absolute" title="Account Login">

                  <mx:Label text="Password:" x="19" y="60"/>

                  <mx:FormItem required="true" x="115" y="34" width="174">
                  <mx:TextInput id="accountInput"/>
                  </mx:FormItem>

                  <mx:Label text="Account Name:" x="19" y="34"/>

                  <mx:FormItem required="true" x="115" y="64">
                  <mx:TextInput id="passwordInput" displayAsPassword="true"/>
                  </mx:FormItem>

                  <mx:Button id="buttonLogin" label="Login" click="validateLogin()" x="174" y="94"/>
                  </mx:Panel>

                  </mx:Form>
                  </mx:Canvas>

                  then i have functions.as
                  [Bindable]
                  public var loginStatus:Object = {loginCheck:int};

                  public function loginHandler(event:ResultEvent):void {
                  loginData = event.result.Character.CharacterInfo;

                  loginStatus.loginCheck = event.result.Status.loggedIn;

                  }

                  Thats the code I have for that stuff.

                  The {loginStatus} never shows properly in the main.mxml it just shows something like [class object] or [object, object], it never shows a value, so the viewstack never changes to the environment. But when I login correctly the loginStatus on the login.mxml shows the change. Maybe you can understand me better now.
                  • 6. Re: Model Problem
                    peterent Level 2
                    Did you try:
                    <mx:Label text="Label: {loginStatus.loginCheck}"/> ?

                    loginStatus is an Object. The text property of <mx:Label> requires a String, so ActionScript invokes the toString() method on the value. loginStatus.toString() yields "[object Object]". Seems like you want the loginCheck property of loginStatus.
                    • 7. Re: Model Problem
                      ForsakenBlade Level 1
                      yes I have tried that then it says [class Int]. or if its a string it says [class string]
                      • 8. Re: Model Problem
                        peterent Level 2
                        I think this may be your problem: In functions.as you have:

                        public var loginStatus:Object = {loginCheck :int};

                        It should be:

                        public var loginStatus:Object = {loginCheck:0};

                        When you create an Object using { } notation (which is different from using { } in data binding) you do not specify the data type, you give constant values. In this case I chose 0 (zero).

                        What the compiler thinks you have done is created a property on loginCheck called int so when you used it with data binding it just printed the data type depending on what you assigned to it.

                        The only 2 places you use data types are in var statements and in function parameter lists and return type:

                        var test :int;
                        var color :Number;

                        function godoit( value :String ) : void {
                        // content of function
                        }
                        • 9. Re: Model Problem
                          ForsakenBlade Level 1
                          well it does display that 0 now but still whenever I actually login the value never changes for neither the custom component or the main application but now it shows the 0 in both.

                          I think because this part may now be wrong, since I've never used an object like this before I may be trying to change the value wrong.

                          loginStatus.loginCheck = event.result.Status.loggedIn;
                          • 10. Re: Model Problem
                            peterent Level 2
                            That may be the case. At this point you should either use the debugger and set a break-point on that line to see what event.result really is or at least use trace statements.
                            • 11. Model Problem
                              ForsakenBlade Level 1
                              I traced the event.result.Status.loggedIn and it is working.

                              The problem is this or so this is what the debugger says.
                              warning: unable to bind to property 'loginCheck' on class 'Object' (class is not an IEventDispatcher)
                              public var loginStatus:Object = {loginCheck:0};

                              but when I do trace(loginStatus.loginCheck) the values change correctly but again on the main.mxml it does not, it continues to say 0 as if it never changed but now the same goes to the login component.
                              • 12. Re: Model Problem
                                peterent Level 2
                                Sorry 'bout that - I forgot an important step. Your object, loginStatus, is just a simple Object. DataBinding on that level works but not on its properties as it must implement IEventDispatch interface and dispatch its own events. Try this simpler way first (create a file called LoginStatus.as with these contents):

                                package {
                                [Bindable]
                                class LoginStatus {
                                public var loginCheck:int;
                                }
                                }

                                Then do:
                                [Bindable] public var loginStatus:LoginStatus;

                                and see if that helps. You may have to make your class extend EventDispatcher, but you should see if this works first.
                                • 13. Re: Model Problem
                                  ForsakenBlade Level 1
                                  Whenever I try to have LoginStatus.as imported to llets say login.mxml it gives an error saying package cannot be nested. What does this mean?
                                  • 14. Re: Model Problem
                                    peterent Level 2
                                    WIthout seeing your files, I'm uncertain what the problem really is. Let's say you have a file LoginStatus.as which should look pretty much as I have it up there from package { to }

                                    In your main file or wherever you want to use it, you wouldn't need an import statement for it because it is in the main application level (the default package). So just use it:

                                    [Bindable] public var loginStatus:LoginStatus;

                                    You'll actually have to do loginStatus = new LoginStatus() at some point, if that wasn't obvious to you.
                                    • 15. Re: Model Problem
                                      ForsakenBlade Level 1
                                      It now gives an error to this....

                                      loginStatus = new LoginStatus();


                                      error: access of undefined property loginStatus.

                                      no matter what i do it always says that.
                                      • 16. Re: Model Problem
                                        peterent Level 2
                                        Do you have:

                                        private var loginStatus:LoginStatus;

                                        someplace? Seems like that is what is missing or it is in the wrong scope.