10 Replies Latest reply on Dec 7, 2007 12:18 PM by Greg Dove

    Why isnt this  working

    DanelKirch
      After a big loss of out-pulled hair here is the code:

      setInterval() calls getNewMess function but it happens nothing with onNewMess function.
      Instead, if i click refresh-button, it gives me result correctly.



        • 1. Re: Why isnt this  working
          Greg Dove Level 4
          getNewMess is expecting an object argument (normally sent by the EventDispatcher from you button click event). Your setInterval call is not providing anything for the argument.
          • 2. Re: Why isnt this  working
            Greg Dove Level 4
            try:

            var intervalID:Number = setInterval(getNewMess, 3000, {target:this.refresh_btn} );
            • 3. Re: Why isnt this  working
              DanelKirch Level 1
              it sounds complicated.
              Is there any other way to trigger same call as button does ?

              I need it reload automatically after every 3 minutes. (it is going to be as system-tray apllication) thats why is button no good solution.
              • 4. Re: Why isnt this  working
                DanelKirch Level 1
                Yep it worked out fine, but it gives me 2 alert messages now ;)
                • 5. Re: Why isnt this  working
                  Greg Dove Level 4
                  the number 3000 in your setInterval is equivalent to 3 seconds because its in milliseconds

                  If you want it to be 3 minutes
                  then it should be 3*60*1000 = 180000

                  • 6. Re: Why isnt this  working
                    Greg Dove Level 4
                    "Is there any other way to trigger same call as button does ?"

                    Yes. If you're not wanting to use the button as well you can. But you will need to change the function getNewMess.


                    • 7. Re: Why isnt this  working
                      Greg Dove Level 4
                      try this, I think it will work for both. :
                      var t=this;
                      function getNewMess(evt:Object) {
                      var pc:PendingCall = t.service.GetNyaMedd();
                      pc.responder = new RelayResponder(t, "onNewMess", "onFault");
                      }

                      //next two functions the same

                      this.refresh_btn.addEventListener("click",getNewMess);
                      var intervalID:Number = setInterval(getNewMess, 180000);

                      /I think that should work
                      • 8. Re: Why isnt this  working
                        DanelKirch Level 1
                        Thanx GWD!
                        It worked out fine!

                        I allmost hated the idea to have to include the button there because i dont want too much components on the stage (even if they are not on the stage).

                        Anyhow. Like you said, it works!
                        • 9. Re: Why isnt this  working
                          DanelKirch Level 1
                          By the way,
                          im using slides / forms in my application and ive included this code allmost everywhere that gets data from amfphp.
                          Is this version better than evt.target._parent ? if so could you explain, why / how ?
                          • 10. Re: Why isnt this  working
                            Greg Dove Level 4
                            evt.target._parent

                            is just using the event argument that is dispatched to and therefore received by your listener function. It is dispatched/sent by your button component instance. The event object from components - in as2 - normally contains at least two properties. A type property... in this case that's "click" , because its a click event and a target property. The target property is a reference to the component instance from which the event originated. It can be particularly useful if you have one listener handling events from many sources. So.....

                            evt.target._parent is referring to the container clip of the instance that sent the event. i.e. The _parent of the button in this case.
                            That's why I replaced it with t (=this) which is a reference to the timeline that the button is running in. Now it doesn't need to get that reference from checking the _parent of the evt.target property from the evt argument. Which means the argument that the newMess function receives can be ignored and its no longer reliant on it. Sounds confusing but once you "get" it, it all makes sense. Eventually, lol.

                            And of couse you don't need to have a button if you don't want one.