2 Replies Latest reply on May 16, 2011 2:58 PM by Kristin95762

    accessing buttons on a custom component from the main app

    Kristin95762 Level 1

      This code from Adobe LiveDocs produces and error. There is no "click" event in the code hints for this implementation. So how do I access the button component in my popup window from the main application? Someone left a comment at the bottom of the page but it was not responded to.

       

       

      Thanks
      
      Kristin

       

       

       

      from: http://help.adobe.com/en_US/flex/using/WS6c678f7b363d5da52e8f1ca1124a0430dcf-8000.html

       

      Error 1009. Cannot access a property or method of a null object reference.

       

      pop1.cancelButton.addEventListener("click", removeMe);
      
      

       
      
      

        • 1. Re: accessing buttons on a custom component from the main app
          blazejewicz Level 4

          Hi,

           

          The code sample in that section:

          http://help.adobe.com/en_US/flex/using/WS6c678f7b363d5da52e8f1ca1124a0430dcf-8000.html#WS6 c678f7b363d5da52e8f1ca1124a0430dcf-7ffe

          ("Passing data using events") works for me without compiler or runtime error.

          It is accessed that way that:

          - PopUpManager creates overlying window (component) which is casted to ArrayEntryFormEvents class.

          - because in ArrayEntryFormEvents instances of components in .mxml are named - including "cancelButton" they could be directly accessed via dot based syntax e.g. that way with re-assign:

           

          var cancelButton:Button = pop1.cancelButton;

          cancelButton.addEventListener(MouseEvent.CLICK, removeMe);

           

          or directly as in sample:

          pop1.cancelButton.addEventListener(MouseEvent.CLICK, removeMe);

          The main application is owner of pop1 instance so it has no problem with accessing "cancelButton" - as it is available directly for dot based syntax being public variable of ArrayEntryFormEvents,

           

          regards,

          Peter

          • 2. Re: accessing buttons on a custom component from the main app
            Kristin95762 Level 1

            thanks for your response.

             

            This is my code in the main app mxml

             

            private function showAddAuthorWindow():void

            {

            authorPopup = new AddAuthorWindow;

            authorPopup.addEventListener(Event.CLOSE, closeHandler);

            authorPopup.addEventListener("addAuthor", addAuthorHandler);

            authorPopup.addEventListener("cancel", closeHandler);

             

            authorPopup.testButton.addEventListener("click", buttonClicked);

             

            PopUpManager.addPopUp(authorPopup, this, true);

            PopUpManager.centerPopUp(authorPopup);

            authorPopup.setInitialFocus();

            }

             

            private function buttonClicked():void

            {

            trace("clicked");

            }

             

            Maybe my problem is that this is not a default button, but one that I added to the popup. Could that be it?

             

            I'm trying to control all the actions of the titlewindow from the main application. I am loading data into a list box in the custom component, etc, etc. I figured I had a lot of code in the titlewindow.mxml that shouldn't be localized there. And I'm way too new at this stuff to be utilizing long winded class files just yet.

             

            Can I load data into a custom control, select, delete, and update data in a custom control through code written primarily in the mainApp.as file?

             

            Thanks

            \

            \Kristin