6 Replies Latest reply on Jul 28, 2008 9:28 AM by Newsgroup_User

    Passing Variables

    lherb3
      Is it possible to create references between action script files so I can pass variables between action script files in flex 3, or am I going to have to use an action script class to do this.

      *Edit **
      I converted an action script file to a class in flex just to find that my program can't exactly call elements on the page by id's, I basically received this error, "1120 Access of undefined property".

      Also what would action script interfaces be used for?

      Thanks In Advance!
        • 1. Re: Passing Variables
          Level 7

          "lherb3" <webforumsuser@macromedia.com> wrote in message
          news:g6khlc$qmi$1@forums.macromedia.com...
          > Is it possible to create references between action script files so I can
          > pass
          > variables between action script files in flex 3, or am I going to have to
          > use
          > an action script class to do this.

          In order for you to use code from a separate AS file, that file either needs
          to be a class that will be imported or it needs to be included, which
          essentially makes it part of the same file (i.e. it has the same scope, so
          no reference is needed). So your question doesn't really make much sense.

          > Also what would action script interfaces be used for?

          An interface is a "contract" that a class agrees to adhere to. This
          essentially says "I have properties a, b, and c and method y which takes an
          argument of type string and returns an object." This means that anything
          that needs to interact with ANY component that implements that interface can
          treat it the same regardless of how those methods are implemented. An
          important thing that you gain with an interface is that any object that
          implements that interface can be treated as if its type is that interface.
          This means that you can easily deal with strongly typed objects of different
          types and get the advantages of code hinting, etc.

          An example of this is that most Flex components implement IDataRenderer,
          which is how you can simply set nearly any Flex component as an itemRenderer
          on a List based component and it just works, even though these components
          are all different types. Conversely, many components do not implement
          IDropInListItemRenderer, so you have to extend the component and implement
          this yourself if you want to use the component to do something more complex
          than just a labelFunction will handle.

          HTH;

          Amy


          • 2. Re: Passing Variables
            Karl_Sigiscar_1971 Level 3
            In ActionScript, interfaces are used for the same purposes as in other languages.

            For example, in the following:
            var myDataProvider:ICollectionView;

            The type of the myDataProvider variable can be any class that implements the ICollectionView interface. ArrayCollection is one such class. Adobe could provide other classes that implement this interface. You could also write a new class of your own implementing the ICollectionView interface.

            By committing to an interface, not an implementation, you give your software more flexibility.
            • 3. Re: Passing Variables
              Karl_Sigiscar_1971 Level 3
              Use the singleton design pattern in order to create a model class whose member variables are accessible from anywhere in the application.
              • 4. Re: Passing Variables
                lherb3 Level 1
                Thanks so much for the feedback
                I apologize if that question may have not made a lot of sense I kind of rushed it.

                So know that I know that action script classes may be the best option for my program I have a completely different problem.

                I know that in flex you can reference a property with an id of something such as id="emailAddress" for something like a text box in this case. And if you wanted to reference that component in an action script file and do something such as setting the width larger, it would be as easy as typing emailAddress.width="200" within an action script file or a script block..

                If I wanted to set the width the same way but this time with an action script class instead of a file, what are the steps that need to be taken in order to set the width of that property?
                • 5. Re: Passing Variables
                  Level 7

                  "Karl_Sigiscar_1971" <webforumsuser@macromedia.com> wrote in message
                  news:g6kmfk$2fc$1@forums.macromedia.com...
                  > Use the singleton design pattern in order to create a model class whose
                  > member variables are accessible from anywhere in the application.

                  It's probably not a good idea to start using a singleton design pattern at
                  that early stage of knowledge. It can become a "crutch" where other design
                  patterns are more appropriate.


                  • 6. Re: Passing Variables
                    Level 7

                    "lherb3" <webforumsuser@macromedia.com> wrote in message
                    news:g6kngq$3kn$1@forums.macromedia.com...
                    > Thanks so much for the feedback
                    > I apologize if that question may have not made a lot of sense I kind of
                    > rushed
                    > it.
                    >
                    > So know that I know that action script classes may be the best option for
                    > my
                    > program I have a completely different problem.
                    >
                    > I know that in flex you can reference a property with an id of something
                    > such
                    > as id="emailAddress" for something like a text box in this case.
                    > And if
                    > you wanted to reference that component in an action script file and do
                    > something such as setting the width larger, it would be as easy as typing
                    > emailAddress.width="200" within an action script file or a script block..
                    >
                    > If I wanted to set the width the same way but this time with an action
                    > script
                    > class instead of a file, what are the steps that need to be taken in order
                    > to
                    > set the width of that property?

                    You probably need to take a step back and spell out exactly what you're
                    trying to do. Where is that class in relation to your field? Why are you
                    trying to put functionality that is addressing that field outside its scope?