2010-07-01 2 views
3

새 프로젝트의 값 개체에서 데이터로드 및 액세스에 문제가 있습니다. 자산 파일의 제목 및 위치가 포함 된 서비스를 통해 XML 파일을로드합니다. 제목을 지정하고 값 객체에서 그것을 retrieiving하여 자산 파일의 위치에 액세스 할 수 있어야합니다 .. 나는 Robotlegs 프레임 워크를 사용하고, 여기에 XML의 예 : - 다음값 개체에서 데이터 채우기 및 액세스

<?xml version="1.0" encoding="utf-8" ?> 
<files id ="xmlroot"> 
<file title="css_shell"     location = "css/shell.css" /> 
<file title="xml_shell"     location = "xml/shell.xml" /> 
<file title="test"      location= "test/location/test.jpg" /> 
<file title ="shell_background_image" location = "images/shell_images/background_image.jpg" /> 
</files> 

내가 이 데이터를 사전 해시 값 개체로 푸시합니다 .. 잘하면

//----------- populate value objects ------------------------------------ 
var xml:XML = new XML(xml); 
var files:XMLList = xml.files.file; 

for each (var file:XML in files) { 
var filePathVO:DataVO = new FilePathVO([email protected](), 
    file.location.toString() 
); 

filePathModel.locationList.push(filePathVO); 
filePathModel.locationHash[filePathVO.title] = filePathVO; 
} 

보기 구성 요소에서 액세스를 테스트했습니다.

// accessing from another class ----------------- 

var _background_image_path:String = String(filePathModel.locationHash['shell_background_image']); 

그것은 어떤 아이디어라도 반환합니까? 당신은이 라인에 위치 속성의 @을 잊어

답변

1

:-)

덕분에 마틴 : 진짜 문제는 라인에 놓여

var filePathVO:DataVO = new FilePathVO([email protected](), 
    file.location.toString()); 

:

var files:XMLList = xml.files.file; 

변경을

var files:XMLList = xml.file; 

xml 변수는 xml의 루트 태그를 나타냅니다. xml.files으로 명시 적으로 액세스 할 필요가 없습니다. xml.files.file은 실제로 files 태그의 직접 하위 인 file 태그를 root-xml 태그의 직접 하위 태그로 찾습니다. 그것은 당신의 XML이 다음과 같았던 것처럼 작동했을 것입니다 :

<?xml version="1.0" encoding="utf-8" ?> 
<root> 
    <files id ="xmlroot"> 
    <file title="css_shell" location = "css/shell.css" /> 
    <file title="xml_shell" location = "xml/shell.xml" /> 
    <file title="test" location= "test/location/test.jpg" /> 
    <file title ="shell_background_image" location = "images/shell_images/background_image.jpg" /> 
    </files> 
</root>