6 Replies Latest reply on Aug 18, 2008 11:02 AM by Newsgroup_User

    Variables

    GeorgeWS Level 1
      I have a file called main.mxml (main file) I also have a file called Cart.mxml. If in the Cart I have a string of variables named tempStr do I use them in the Main.mxml? Im thinking like this: Alert.show(tempStr) but Thats doesnt work.
      Any thoughts?
      Thanks
      George
        • 1. Re: Variables
          Michael Borbor Level 4
          your variable must be set to public so it can be access externally.
          • 2. Re: Variables
            Gregory Lafrance Level 6
            You also need the id of the Cart inside Mani.mxml

            var myCart:Cart = new Cart();
            trace(myCart.tempStr);
            • 3. Re: Variables
              GeorgeWS Level 1
              How does the Main.mxml get the variable. With a public function? If so how do you trigger this function? On my Cart.mxml im doing this to show me all the items in my cart.

              public function checkOut():void {

              var tempStr:String = "Your cart contains: \n";
              for (var i:int = 0; i < cartAryCol.length; i++) {
              tempStr = tempStr + cartAryCol .PNUM5W + "\n" ;
              }
              Alert.show( tempStr );
              }

              But instead of the Alert being in the Cart.mxml I want to use the tempStr in the Main.mxml and I cannot seem to.

              Thanks

              George
              • 4. Re: Variables
                Level 7

                "GeorgeWS" <webforumsuser@macromedia.com> wrote in message
                news:g8c5cc$7u1$1@forums.macromedia.com...
                > How does the Main.mxml get the variable. With a public function? If so how
                > do
                > you trigger this function? On my Cart.mxml im doing this to show me all
                > the
                > items in my cart.
                >
                > public function checkOut():void {
                >
                > var tempStr:String = "Your cart contains: \n";
                > for (var i:int = 0; i < cartAryCol.length; i++) {
                > tempStr = tempStr + cartAryCol .PNUM5W + "\n" ;
                > }
                > Alert.show( tempStr );
                > }
                >
                > But instead of the Alert being in the Cart.mxml I want to use the tempStr
                > in
                > the Main.mxml and I cannot seem to.

                Generate an event from your cart, then look at the data that is carried by
                the event. Since tempStr is local to your checkOut() function, you will not
                be able to directly access it in the event. If you made it public you could
                do something like:

                var cs:String = event.currentTarget.tempStr;

                Or you could create a custom event that carries the information in a custom
                property. http://www.adobe.com/devnet/flex/videotraining/

                The Flex 3 Training From the Source book walks you through creating a
                shopping cart application.


                • 5. Re: Variables
                  GeorgeWS Level 1
                  Where do you put this? main.mxml or cart.mxml:

                  var cs:String = event.currentTarget.tempStr;

                  and how do you call it? Do you have an example?

                  Thanks

                  George
                  • 6. Re: Variables
                    Level 7

                    "GeorgeWS" <webforumsuser@macromedia.com> wrote in message
                    news:g8c9o0$cj7$1@forums.macromedia.com...
                    > Where do you put this? main.mxml or cart.mxml:
                    >
                    > var cs:String = event.currentTarget.tempStr;

                    That would be in the event handler in your main.mxml that you set up to
                    catch the event you dispatched in cart.mxml

                    > and how do you call it? Do you have an example?

                    Try doing a search on Flex event handling or looking at the flex in a week
                    training or buying Flex 3 training from the source.