8 Replies Latest reply on Nov 20, 2008 9:01 AM by Rothrock

    need help creating functions

    Sketchsta Level 1
      Hey guys, I'm in need of a function that 'searches' a movieclip for textfields. There is no set amount of textfields, meaning there will always be a different number of textfields in this movieclip. Then I need to send all these textfields to a PHP script, for mailing to a email.

      Thanx in advance for any help regarding this function, and/or any suggestions of a better way to go about getting this Order Basket idea to work.

      quick info:
      The idea here is a Order Form. There are hundreds of items, which the viewer goes through and selects the ones they want. When they click on a [Add to Cart] button, a function will be called to create textfields inside a separate movieclip, with the Item ID pre-set, and some Input textfields for options like 'color, size, quantity' etc..
      When the viewer opens this movieclip (shopping basket) all the added items will be displayed, along with they're choices of color, size, etc..
      a [Place Order] button at the bottom will need a function to search for the amount of textfields inside this movieclip (shop basket) and send the values of each field to a PHP script, for mailing.
        • 2. Re: need help creating functions
          Rothrock Level 5
          I think a better approach might be to push the "ordered" item into an array. Then when they go to their shopping cart, create clips and textfields from the array.
          • 3. Re: need help creating functions
            Sketchsta Level 1
            Thanx kglad, works like a charm. =)
            Now I just need to format the output into categories and sub categories.
            eg.. Item 1 (category) Item 1 color (sub category)

            I am not too familiar with Arrays, so I don't know how to create clips and fields from an array. I guess it couldn't be too hard tho.
            What would be the advantage of doing it this way?
            • 4. Re: need help creating functions
              Rothrock Level 5
              To me it just seems to make sense. Keep a list of the things you need, make those things. As opposed to randomly do some stuff without paying attention to it and then find it later.

              You also mention formating the output. I'm not quite clear on exactly what you mean there, but if you mean that the order they selected items might not be the order it is displayed in, then arrays make sense too. Arrays are made to hold chunks of info and then do things with them. So if you need to sort things arrays are good for that. To me it makes more sense to collect some info organize it and then do something with it.

              Since the things you need to find are being created by user action it should be easy to track them. The exact nature of how to set it up depends upon a lot of things so I can't be sure exactly what to tell you. But here is some general outline.

              Before you begin somewhere create an array perhaps something like this:

              var curOrder:Array=new Array();

              Then somewhere you could define your different catalog items. I would probably use objects. Depending upon your needs you may do something completely different but anyways something like this:


              Of course your code could get the values to put after the object properties from the text fields. Then when it comes time to generate your shopping cart you can just go through all the items in the array:

              for(var i=0;i<curOrder.length;i++){
              var curItem=curOrder ;
              // create a clip for the curItem
              // add some text to the clip
              // etc.

              Let's say you wanted all things of each color together you could use use the sort on before your loop. Something like this:


              • 5. Re: need help creating functions
                Rothrock Level 5
                I always forget that [ i ] makes things italic. So here

                for(var j=0;j<curOrder.length;j++){
                var curItem:Object=curOrder[j];
                • 6. Re: need help creating functions
                  kglad Adobe Community Professional & MVP
                  you're welcome.
                  • 7. Re: need help creating functions
                    Sketchsta Level 1
                    I think you know exactly what im looking for. I have a small job to do real quick, a few days at most. I wouldn't have much time to practice what you teach me.
                    Would you still help me with your idea when i come back to this Shopping Basket please?

                    ohh and sorry for not being clear on what I mean by Formatting the output.
                    What I meant was, formatting the text from an array when displaying the viewer's order.
                    If I was to do it your way, and read from the array, then create a textArea to display the contents (order), I would like the text to be formatted like..eg..

                    Item 1 - Jeans
                    color - black
                    size - XL
                    quantity - 20

                    Item 2 - Shirt
                    color - orange
                    size - L

                    then at the end, I will need to send this info (order) to a PHP script, which will send the info to a email. I hope there is a way to keep the text format/layout when sending to email.

                    anyway, I hope to be back at this really soon, I think it's about time i learn more about arrays and they're benefits.
                    Thank you for all your help so far. =)
                    • 8. Re: need help creating functions
                      Rothrock Level 5
                      Sure. Complete whatever project you need to in the best way you can. But I really recommend that this approach will be very useful for all sorts of things in the future. So when you have a chance learn it. :)