두 가지 기능이 있습니다. submitIngredientChoices
,이 변수는 검색어 문자열에 /?i=chicken,lamb,pesto&q=italian&format=xml
형식의 Recipe Puppy라는 웹 사이트로 전달됩니다. 웹 사이트에는 공개 API가 있으며 XML 문서가 반환됩니다.URLLoader에서 XML 데이터를 사용하는 DataGrid
두 번째 함수 인 recipeResults()
은 dataProvider를 URLLoader 데이터 (loader.data
)로 설정하여 DataGrid를 인스턴스화합니다. 데이터는 DataGrid로로드되지만보기에는 좋지 않지만 일부 열을 하이퍼 링크로 표시 할 텍스트로 표시합니다.
function submitIngredientChoices(event:MouseEvent):void {
var url : String = 'http://www.recipepuppy.com/api/';
// url variables all which will appear after ? sign
var urlVariables : URLVariables = new URLVariables();
var ingredients:Array = [so.data.meat1, so.data.meat2, so.data.meat3,
so.data.veg1, so.data.veg2, so.data.veg3,
so.data.carbs1, so.data.carbs2, so.data.carbs3];
var others:Array = [so.data.other1, so.data.other2, so.data.other3,
so.data.cuisine1, so.data.cuisine2, so.data.cuisine3,
so.data.mealtype1, so.data.mealtype2, so.data.mealtype3];
urlVariables['i'] = ingredients.join();
urlVariables['q'] = others.join();
urlVariables['format'] = "xml";
// creating new URL Request
var request:URLRequest = new URLRequest (url);
// setting the variables it need to carry
request.data = urlVariables;
// setting method of delivering variables (POST or GET)
request.method = URLRequestMethod.GET;
trace(request.data);
// creating actual loader
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, recipeResults);
loader.load(request);
}
그리고 내 데이터 그리드 기능 :
function recipeResults(event:Event):void {
addChild(_dataGrid);
var xmlDP:XML = new XML(loader.data);
// create a new data provider with this and register it with the DataGrid
dp = new DataProvider(xmlDP);
dataGrid.dataProvider = dp;
}
나는 xmlParse
기능을 갖는 것은이에 대한 해결책이 될 것이라고 알고 있지만, 어떻게 내 데이터 그리드가 자동으로 파싱이 발생하지 않고 구문 분석되지 않은 XML 문서를로드?
아래 코드를 쉽게 적용하여 열을 변경하는 방법과 하이퍼 링크로 내 xml 데이터의 a href
열을 얻는 방법을 알고 싶습니다.
EDIT : AS2에 익숙하지만 AS3의 새로운 주요 기능 중 하나가 자동 XML 구문 분석이라는 것을 알았습니다. (맞습니까?) 어쨌든 내 질문은 여전히 의미합니다. DataGrid의 모양과 느낌을 바꿉니다 (예 : XML 요소에 액세스하여 DataGrid의 열에 특성을 부여하는 방법)
당신이 플렉스의 데이터 그리드를 사용하고 다음은 그 일에 대한 자습서이다? – Kodiak
@Kodiak 아니요, 플래시 전문가 – adaam