2 Replies Latest reply on Aug 3, 2009 6:09 AM by Gregory Lafrance

    Passing VARs between flex components

    Vitor Wsis

      Hi,

       

      How can i passing VARs between flex components?


      I try: public var TypeGaleria:String="Fotos";

      but doesn't work!

        • 1. Re: Passing VARs between flex components
          nickmiddleweek Level 1

          The preferred way of passing vars between components is by using Data Active Objects (or Value Objects). These are then bound to a Custom Event Class which is then dispatched by Component A and handled by the main Application and passed into Component B.

           

          If this concept is new to you, you might want to check out these video's... It may take a while to get your head round it but it will make sense once it 'clicks' with you. http://www.adobe.com/devnet/flex/videotraining/ - Start on Day with the video: Binding data between controls...

           

          If you want to do direct binding (or accessing Global variables) which is usually considered bad practice then I think you'll need to create the public var myVar:String in both components and set each one to be [Bindable]. Then the two should update in each component and main application space.

           

          [Bindable]

          public var myVar:String;

           

           

          This is bad practice because you are tying together your components, when they should work independantly of each other without having to reach in and set/get the variables directly.

           

           

          Hope this help...

           

          Nick

          1 person found this helpful
          • 2. Re: Passing VARs between flex components
            Gregory Lafrance Level 6

            You can communicate between the main app and components, and between components using "mx.core.Application.application" (or parentApplication and parentDocument), but that is considered bad practice, as it results in a tightly coupled application.

             

            import mx.core.Application;

             

            public var app:Object = mx.core.Application.application;

             

            myComp1 = app.myComp2.myVar;

             

             

            For a loosely coupled application, use custom events to pass data around. Here is my Flex cookbook post on using custom events in a MVC based wizard:

             

            http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postI d=11246

             

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