3 Replies Latest reply on Mar 31, 2010 8:37 AM by Raconteur

    Simple app but cannot figure out


      Hi all,

      I have a Flex app with a form (one drop-down list and 3 input fields).  The button on the form should take the four values and roll them into an object (a Node), and then add them to an array which is represented on the same screen by a list box.

      I made the Node class in a separate file.  I also made the form in a separate file.

      The main Flex app (file) has <forms:NodeForm> to put the form on the screen.  Then should come the list box with the results.

      Here is where I run into trouble... First off how do I get the click event handled in a different page?  The handler cannot live in the form file, it needs to live in the main screen.  Then, in the button click handler I need to instantiate the Node class, fill it with the data scraped from the screen and then stuff it into an array that is the underlying data model for the list box.  That should be all of 3 lines of code or so, but I cannot find them.

      This cannot be difficult, but I can't find a reference that talks about building a data structure programmatically that is surfaced on the same screen as the form.


      Any input greatly appreciated!





        • 1. Re: Simple app but cannot figure out
          Gregory Lafrance Level 6

          You can listen for the button click in the main application and check the currentTarget property of the event object.


          You should be able to create nodes in the main app too.


          Although custom events are best for communicating among the main app and components, you can use mx.core.Application.application, or parentApplication, and sometimes parentDocument.


          If this post answers your question or helps, please mark it as such.

          Greg Lafrance - Flex 2 and 3 ACE certified


          • 2. Re: Simple app but cannot figure out
            Raconteur Level 1

            Hi Greg,


            Thanks for the response.  Couple of more specific questions... how do I set up the event handler in a separate file?  I cannot seem to get to the contents of the form from the parent page, to attach to the button.  Do I need to bubble the event up?


            Also, what incantation do I need to make to create an Array (or ArrayList) programmatically, fill it, and attach it to the List control?  I know how to make the Array and fill it, it is the attaching that is eluding me.





            • 3. Re: Simple app but cannot figure out
              Raconteur Level 1

              Hi Greg,


              Ok... I got the first bit sorted.  I was not giving the form an ID, and the way I was referencing it was through the class name, which is why I could not get to the controls on the form.


              Now, I have the nodes array built and populated, but I cannot get it attached to the List control.  In the main page, I have a <fx:Script> section where I am importing the node class, ArrayList, and instantiating the ArrayList (nodes).  But when I try to do something like <s:DataGroup height="300" width="240" dataProvider="{nodes}"> I get a warning that nodes may not be visible.


              What am I missing here?