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