0
我正在编写一个移动应用程序,用户可以将配料与配方匹配。我已经跨越http://www.recipepuppy.com/about/api/它提供了一个非常简单的API通过逗号来搜索偶然分离的成分,例如:将AS3中的数据传递给查询字符串(API)
http://www.recipepuppy.com/api/?i=onions,garlic&format=xml
我有存储在共享对象像这样的各种成分:
so.data.meat1 = "beef"
so.data.meat2 = "chicken"
so.data.meat3 = "lamb"
so.data.veg1 = "green beans"
etc etc..
我完全新到AS3,所以我不知道可以实现这一点的主要方法/类。
所以 1.如何将我的共享对象的数据传递到上面的配方puppy的url的查询字符串中? 2.如何将XML结果加载到数据网格或类似组件中?
编辑:这是我这么远:
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);
它的工作很好,但我目前使用URLVariables的设置[“我”]只允许我指定一个“我”的变量,如何为“i”变量指定多个变量值?
'urlVariables ['i'] = so.data.meat1 +“,”+ so.data.meat2'或者将数组保存在数组中,例如:'var ingredients:Array = [so.data.meat1,so.data .meat2];'然后使用连接像这样:'urlVariables ['i'] = ingredients.join();' – 2013-04-28 19:41:38
谢谢你看起来正确,你可以发布它作为答案,所以我可以接受? – adaam 2013-04-28 19:45:36