5 Replies Latest reply on Aug 27, 2007 9:52 AM by Newsgroup_User

    ViewStack External File Cannot Access AS Script

    scooter5791 Level 1
      Hello,

      I am very new to both Flexbuilder and Actionscript so I am going to need some help please. I have a main mxml file that contains a ViewStack as well as an external AS file. The problem is that I am using external mxml files for the ViewStack that need to call functions in the external AS script file which is included in the main mxml. I am gettting compiler errors in these external mxml files (Call to possibly undefined method ) because they cannot access the external AS functions since this file is included only in the main mxml.

      Everything worked great when I had all the code in one main file, but I am trying to get a handle on separating the AS code from the mxml code as well as trying to use external mxml modules in the ViewStack. Can someone give me some pointers how to successfully separate everything and make it work?

      Thanks in advance...

      Scott
        • 1. Re: ViewStack External File Cannot Access AS Script
          scooter5791 Level 1
          Ok, I figured it out. In the external mxml module I needed to call the AS functions using the parrentApplication prefix (scope?) such as:

          <mx:Button ...{normal attribute here} ... click="parentApplication.myFunction()" />

          This allows the compiler to know where the actual function code resides.

          Is this the preferred way to do this or are there other things I should be aware of? Thanks as always.

          Scott
          • 2. Re: ViewStack External File Cannot Access AS Script
            Level 7

            "scooter5791" <webforumsuser@macromedia.com> wrote in message
            news:fak7qt$7vp$1@forums.macromedia.com...
            > Ok, I figured it out. In the external mxml module I needed to call the AS
            > functions using the parrentApplication prefix (scope?) such as:
            >
            > <mx:Button ...{normal attribute here} ...
            > click="parentApplication.myFunction()" />
            >
            > This allows the compiler to know where the actual function code resides.
            >
            > Is this the preferred way to do this or are there other things I should be
            > aware of? Thanks as always.

            You can use the import statement to import the class into the child file, or
            you could broadcast an event that tells the parent to run the function
            instead. Referring to the parent function is only a good idea if you want
            to create a situation where the chld component only works within that same
            structure (tightly coupled).

            HTH;

            Amy


            • 3. Re: ViewStack External File Cannot Access AS Script
              scooter5791 Level 1
              Currently my AS code is not a class file. I just moved the <mx:script... code into an .as file so it contains only a collection of functions. I am not sure if broadcasting an event for the parent to handle would be a good idea either since I have literally dozens of functions in that file. Basically this is a small application which accesses a specific web services API and most of the functions are for either calling a service or for handling the results. For my immediate purposes I think this loose-coupling will be fine. But if my child components were created to be reusable across numerous applications then I definitely see your point. I may have to rethink my next application and find a better approach. Thanks for the response.
              • 4. Re: ViewStack External File Cannot Access AS Script
                scooter5791 Level 1
                I found a helpful article series covering exactly what you are saying Amy. The 3-part series by Thomas Ortega (link below) opened my eyes and made some sense of it all. I have a good development background in other languages and technologies and I certainly understand the importance of good achitecture. I just don't have any real experience with Flash, Actionscript or Flex (yet) so I didn't really have knowledge of best practices yet. Thanks again for your reply.

                http://www.adobe.com/devnet/flex/articles/graduating_pt1.html
                • 5. Re: ViewStack External File Cannot Access AS Script
                  Level 7

                  "scooter5791" <webforumsuser@macromedia.com> wrote in message
                  news:famjgt$b3$1@forums.macromedia.com...
                  >I found a helpful article series covering exactly what you are saying Amy.
                  >The
                  > 3-part series by Thomas Ortega (link below) opened my eyes and made some
                  > sense
                  > of it all. I have a good development background in other languages and
                  > technologies and I certainly understand the importance of good
                  > achitecture. I
                  > just don't have any real experience with Flash, Actionscript or Flex (yet)
                  > so I
                  > didn't really have knowledge of best practices yet. Thanks again for your
                  > reply.
                  >
                  > http://www.adobe.com/devnet/flex/articles/graduating_pt1.html

                  Yes, I am anxiously awaiting part 3.