5 Replies Latest reply on Aug 9, 2010 8:44 AM by rtalton

    HTTPService Questions

    Joshfromdallas Level 1

      I am using Flash Builder 4.


      I have a Air app that i am working on that is for employees to use to create orders. The app is online and offline so it caches the orders using shared object. When the user is connected they upload the order using a PHP HttpService to a mysql db.


      Each order has items that are added, so there are two Arraycollections - Orders and OrderItems.


      The problem is when the upload progress happens i need to get the orderId from the order upload to add to each item so they match on the server SQL. I use UID locally to match them up, but my fear is that another user may create a duplicate UID, since it says it is created on a date formula.


      My other issue is how can i have it remove the item form the arraycollection after it has been uploaded.


      I've done a little research and I think I need to make a synchronous httpservice request to upload the order, return the order id then update the items with the order id, then upload the orderItems.


      Sorry for the long post and thanks in advance for any advice.

        • 1. Re: HTTPService Questions
          rtalton Level 4

          The HTTPService is always asynchronous.


          If it were me...

          When sending the order back to the server, also attach the related "items" by merging these together into one object. On the back-end, have your service layer split them up and do the relevant database INSERTs (in .NET lingo, it would be a "transaction"). Return the INSERT result (success, fail) back to Flex.


          When you send the order to the db, use the AsyncToken class to add a unique order/item value(s) which will then be returned from your service layer INSERT result. The UIDs will work fine. You can attach multiple values to a token, and parse them when they are returned in the ResultEvent or FualtEvent. Then you will know which affected order/items you need to remove from the view if the INSERT was successful. To find the order/items and remove them from your ArrayCollection, use a cursor to search for them in the order/item ArrayCollections. When found, use removeItemAt().



          • 2. Re: HTTPService Questions
            Joshfromdallas Level 1

            How do I merge them into one object, I have trying to accomplish this but have been unsuccesful so far.


            Thanks for the advice, it makes sense, now if I could only make it work

            • 3. Re: HTTPService Questions
              rtalton Level 4

              I'm not a PHP guy, so I can't help with your back-end scripting.

              Looking at this again, let me change my answer to recommend sending the data as two discrete objects, without trying to merge them together. See if your PHP script will let you accept two objects for processing.

              If PHP cannot do this, you're back to merging. If it's not a lot of data, loop through both the "orders" & "items", adding them to a third, empty, ArrayCollection (or whatever data structure PHP will accept), then send that AC to PHP. On the back end, you should be able to loop through it with PHP and split it back into two pieces.

              • 4. Re: HTTPService Questions
                Joshfromdallas Level 1

                Thanks for the pointer,


                May I ask what you use to connect your Flex app to the backend SQL?


                I am new to Flex so I am just learning along the way and PHP looked easy to make work, I assume there is a better way since it seems I am busting my balls trying to get these to work.

                • 5. Re: HTTPService Questions
                  rtalton Level 4

                  I'm using .NET.     PHP is widely used and there are lots of tutorials out there, including on the Adobe site.