8 Replies Latest reply on Nov 26, 2012 1:00 PM by sinious

    Event Listeners

    Rennan Reis

      Hello guys, how are you?

       

      I'm working with ActionScript 2 Event Listeners and have a question about adding listeners in an ActionScript Class.

       

      I tried this way in the constructor method:

       

      this.onLoad = loadXML;
      this ['btnNext']. onRelease = loadNext;
      this ['btnPrevious']. onRelease = loadPrevious;
      this ['btnLearnMore']. onRelease = learnMore;

       

      This are the respective methods:

       

      private function loadXML () {};
      private function loadNext () {};

      ...

       

      I'm rusty with actionscript 2. So, does anyone could help me?

       

      Regards,

        • 1. Re: Event Listeners
          sinious Most Valuable Participant

          Events will be sent to those functions so you should set an event argument up to capture them (loadNext(e){} at minimum).

           

          What exactly are you having a problem with using the above code?

          • 2. Re: Event Listeners
            Rennan Reis Level 1

            I'm trying to create an actionscript class called NewsListing. Within Fla file, I have a movieclip called NewsListing. I wish some listeners were activated immediately when I created the object Movieclip NewsListing.

             

            This is class file: rennanreis.com/flashnewslisting.zip


             

             

            I´m have more skills with AS3, but I need to review AS2 for a task

             

            I will be very grateful if you can help me.

            • 3. Re: Event Listeners
              sinious Most Valuable Participant

              You're assigning this.onLoad to loadXML, not the xmlObj you defined. "this" is the class "NewsListing" so you're going to want to apply the listener to the XML instance, e.g. xmlObj.onLoad = loadXML;

              • 4. Re: Event Listeners
                Rennan Reis Level 1

                Got it. So, I must use the same rule to other objects that have a listener. Right?

                • 5. Re: Event Listeners
                  Rennan Reis Level 1

                  I tried what you mentioned earlier. But it still does not work. The XML file isn´t load. Do You know what it could be?

                   

                   

                  Regards,

                   

                  Rennan

                  • 6. Re: Event Listeners
                    sinious Most Valuable Participant

                    Yep other objects that have a listener can be assigned in the same way, or you can use anonymous functions (xmlObj.onLoad = function(e) {};).

                     

                    What errors are you getting? Here's some code directly from the AS2 ref about handling errors. Something should pop up to help you locate the status of the load. Add them before you run the .load() method:

                     

                    xmlObj.onHTTPStatus = function(httpStatus:Number)

                    {

                        if (httpStatus < 100) { trace("flashError"); }

                        else if(httpStatus < 200) { trace("informational"); }

                        else if(httpStatus < 300) { trace("successful"); }

                        else if(httpStatus < 400) { trace("redirection"); }

                        else if(httpStatus < 500) { trace("clientError"); }

                        else if(httpStatus < 600) { trace("serverError"); }

                    }

                     

                    xmlObj.onLoad = function(success:Boolean)

                    {

                        if (success)

                        {

                            if (my_xml.status == 0) { trace("XML was loaded and parsed successfully"); }

                            else { trace("XML was loaded successfully, but was unable to be parsed."); }

                           

                            var errorMessage:String;

                            switch (my_xml.status) {

                            case 0 :

                                errorMessage = "No error; parse was completed successfully.";

                                break;

                            case -2 :

                                errorMessage = "A CDATA section was not properly terminated.";

                                break;

                            case -3 :

                                errorMessage = "The XML declaration was not properly terminated.";

                                break;

                            case -4 :

                                errorMessage = "The DOCTYPE declaration was not properly terminated.";

                                break;

                            case -5 :

                                errorMessage = "A comment was not properly terminated.";

                                break;

                            case -6 :

                                errorMessage = "An XML element was malformed.";

                                break;

                            case -7 :

                                errorMessage = "Out of memory.";

                                break;

                            case -8 :

                                errorMessage = "An attribute value was not properly terminated.";

                                break;

                            case -9 :

                                errorMessage = "A start-tag was not matched with an end-tag.";

                                break;

                            case -10 :

                                errorMessage = "An end-tag was encountered without a matching

                                start-tag.";

                                break;

                            default :

                                errorMessage = "An unknown error has occurred.";

                                break;

                            }

                           

                            trace("status: "+my_xml.status+" ("+errorMessage+")");

                        }

                        else

                        {

                            trace("Unable to load/parse XML. (status: "+my_xml.status+")");

                        }

                    }

                    1 person found this helpful
                    • 7. Re: Event Listeners
                      Rennan Reis Level 1

                      Sorry, I had problems applying the onLoad within an actionscript class. Now already fix the problem.

                       

                       

                      Thank you for your help!

                      • 8. Re: Event Listeners
                        sinious Most Valuable Participant

                        Glad you resolved your issue. If you're all set please mark the thread correct so we can find unanswered questions.

                         

                        You're welcome and good luck!