3 Replies Latest reply on Jul 7, 2008 10:44 AM by VarioPegged

    About reaching up into a parent document

      This little application has been the subject of a couple of other recent threads in this forum: http://www.timos.com/timos/greenEarth/GreenEarth.html. Looking at it will make my question very clear. Source view is enabled. VarioPegged previously helped me with the application, hence the subtopic label.

      I am very new to Flex, AS and OOP, but from reading about these things, I also cringe when I see Application.application.xxx or parentDocument.xxx. I view this as contrary to the concepts of OOP and 'loosely coupled architecture'.

      In the application, there is a video that appears in a view state called 'video' (press anywhere in the box where a picture of a young lady appears, second image down on the right); I tell users to press the 'Exit video' button when they are done with it.

      The code for the 'Exit video' button's click handler includes 'Application.application.currentState='intro'. I did it this way'because I could not figure out what event to dispatch and who should dispatch it.

      I am hoping someone has time to take look and provide the right code, or at least a hint about how to do this.

      Regards to all,

        • 1. About reaching up into a parent document
          VarioPegged Level 2
          You're right, it's a good thing to strive for good app design.

          I've made it known that I advocate designing components that could be reused or adapted with minimal effort regardless of their context. This is one of the reasons why I'm against Application.application and other methods where the child sets properties on the parent, or the parent of the parent. Using those methods, in my opinion, is backwards. Parents should set properties on children. This is how the components/controls work within the Flex framework.

          To address your issue, you might dispatch a 'close' or 'exit' event from SuzukiVideo.mxml and simply assign a listener inline in the main app.

          Now some may say that it's just plain silly to have all that extra code dispatching events and what not, when all it takes is a single line of code to accomplish the same thing. That's true, but I can guarantee that using events and listeners is the only way to go as the complexity of your application grows.

          In the same breath I will say that you'll probably find times when using the dreaded Application.application is the only way out; after all, the Flex engineers included it in the API. Fortunately yours isn't one of those times.

          • 2. Re: About reaching up into a parent document
            cheftimo Level 2
            OK, TS, you definitely rule! It's great to be rid of that 'Application.application'.

            I had tried the Metadata bit (with a different event name), but couldn't figure out where to go from there. Now the way to do this is tattooed in my brain.

            Because of the name similarity, on the main application, it's easy to confuse <c:SevernSuzuki> with <v:SuzukiVideo>, the latter being the one that should contain the code exit="currentState='intro'". I am glad I had to figure that out because now I know exactly how this works.

            You have been very helpful, thank you so much. I'll keep looking for your name to read everything you post. Best regards,

            • 3. Re: About reaching up into a parent document
              VarioPegged Level 2
              Carlos, you're welcome. Good catch re the class/instance that exit="currentState='intro'" should be added to.


              I'll keep looking for your name to read everything you post.

              That's just too much pressure ;)