0

I'm writing a mobile app where a user can match ingredients to recipes. I have stumbled across http://www.recipepuppy.com/about/api/ which provides a very simple API to search by comma separated ingredients such as:

http://www.recipepuppy.com/api/?i=onions,garlic&format=xml

I have various ingredients stored in a shared object like so:

so.data.meat1 = "beef"
so.data.meat2 = "chicken"
so.data.meat3 = "lamb"
so.data.veg1 = "green beans"
etc etc..

I am completely new to AS3, so I don't really have an idea of the main methods / classes that could achieve this.

So 1. How can I pass my shared object's data into the query string of recipe puppy's url above? 2. How would I load the XML results into a datagrid or similiar component?

edit: this is what I have got so far:

var url : String = 'http://www.recipepuppy.com/api/';

            // url variables all which will appear after ? sign
            var urlVariables : URLVariables = new URLVariables ();
                urlVariables['i'] = so.data.meat1;
                urlVariables['i'] = so.data.meat2;
                urlVariables['format'] = "xml";
                // here you can add as much as you need

            // creating new URL Request
            // setting the url
            var request : URLRequest = new URLRequest  ( url );
                // setting the variables it need to cary
                request.data = urlVariables;
                // setting method of delivering variables ( POST or GET )
                request.method = URLRequestMethod.GET;

            // creating actual loader
            var loader : URLLoader = new URLLoader ();
                loader.load ( request );
                trace(request.data);

It's working well, but my current setup of the urlVariables['i'] only allows me to specify one 'i' variable, how do I specify multiple variable values for the 'i' variable?

2
  • 1
    urlVariables['i'] = so.data.meat1+","+so.data.meat2 or keep ingredients in an array like so: var ingredients:Array = [so.data.meat1,so.data.meat2]; then use join like so: urlVariables['i'] = ingredients.join(); Commented Apr 28, 2013 at 19:41
  • Thank you that looks about right, can you post it as answer so I can accept? Commented Apr 28, 2013 at 19:45

1 Answer 1

1

OK, for an answer I need to enhance it:)

first you should store ingredients as an array in SO, like shown here SharedObject#data

so.data.ingredients = ["beef","chicken","lamb"];

then you can pass it to the urlVariables as:

urlVariables['i'] = so.data.ingredients.join();

of course I would add som tests if the so.data.ingredients exists to acoid any errors thrown,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.