2014-04-25 6 views
0

실제로이 코드는 stackoverflow 자체에서 발견되었습니다. xml을 mxml에로드 한 다음로드 된 데이터를 원형 차트 나 막대 그래프로 변환하려고합니다. 다음과 같이 코드는 다음과 같습니다mxml (Adobe Flex)에 xml 파일로드

<?xml version="1.0" encoding="utf-8"?> 
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         creationComplete="load()"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here -->   
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 

      // this is a variable definition so it is good 
      var xmlLoader:URLLoader = new URLLoader(); 

      // these two lines are code that executes; so they must be put inside a method; something you did not do. Comment them out 
      //xmlLoader.addEventListener(Event.COMPLETE, loadXML); // 1st error here 
      //xmlLoader.load(new URLRequest("books.xml")); // 2nd error here 

      // this is a variable definition so it is okay 
      var xmlData:XML = new XML(); 

      // this is a function definition so it is okay 
      function loadXML(e:Event):void{    
       xmlData = new XML (e.target.data);    
      }    

      // move your executing code into a method 
      public function load():void{ 
       xmlLoader.addEventListener(Event.COMPLETE, loadXML); 
       xmlLoader.load(new URLRequest("books.xml")); 
      } 
     ]]> 
    </fx:Script> 

    <s:VGroup>  
     <s:TextArea id="txtArea">  
     </s:TextArea>    
    </s:VGroup> 

</s:WindowedApplication> 

그것은 I에 유래에서 발견 코드를합니다. 하지만 여전히 코드를 실행할 수는 없습니다.

하고 XML 파일은 다음과 같은 것입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<Books> 
<Manager Man_id="1" Man_Name="P.Ananth"/> 
<Manager Man_id="2" Man_Name="Gokulakrishnan"/> 
<Manager Man_id="3" Man_Name="Stani"/> 
</Books> 

내가 초래하고있어 오류가 이것이다 : - 구성 요소 클래스 'loader2'에 대한 지정된 기본 클래스 'spark.components.WindowedApplication'를 찾을 수 없습니다 . loader2.mxml -/loader2/src - 알 수없는 플렉스 문제

답변

0

프로젝트가 플렉스 프로젝트 인 것 같습니다.

WindowedApplication은 AIR SDK에 포함되어 있습니다. 프로젝트가 응용 프로그램 프로젝트 여야 함을 의미합니다.

시도,

  • <s:WindowedApplication>-

추가 <s:Application> :

은 URLLoader 매우 중요한 클래스이지만, 당신은 일반적으로 HTTPService를를 사용할 수 있습니다. 그것은 간단하지 않다

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" 
       creationComplete="service.send()"> 

    <fx:Declarations> 
     <s:HTTPService id="service" resultFormat="e4x" url="books.xml"/>   
    </fx:Declarations> 

    <s:VGroup> 
     <s:TextArea id="txtArea" width="100%" text="{service.lastResult}"/>  
    </s:VGroup> 

</s:Application> 

:

는의 위의 코드와 동일하게 수행하는 코드를 살펴 보자?

URLLoader는 as3 클래스이고 Flex 프레임 워크는 as3을 기반으로합니다. HTTPService는 쉽고 편리한 기능을 제공하는 Flex 구성 요소입니다. 내부적으로 URLLoader를 사용합니다.

+0

고마워요. 오류가 사라지더라도 세 가지 경고가 표시되며 브라우저에 아무 것도 표시되지 않습니다. 경고는 다음과 같습니다 : (1)이 줄에 여러 개의 표식이 있습니다. -1084 : var 'xmlLoader'의 범위가 기본 네임 스페이스 인 loader2 : internal로 지정됩니다. 이 패키지 외부에는 보이지 않습니다. - 라인 중단 점 : loader2.mxml [행 : 15] (2) 1084 : var 'xmlData'의 범위가 기본 네임 스페이스 인 loader2 : internal로 지정됩니다. 이 패키지 외부에는 보이지 않습니다. (3) 1084 : 'loadXML'함수의 범위가 기본 네임 스페이스 인 loader2 : internal로 지정됩니다. –

+0

@Nav_cfc 이제 경고를 무시합시다. 'var xmlData : XML ... '앞에'[Bindable]'을 추가하고'' 태그에'text = "{xmlData}"를 추가하십시오. 그러면 뭔가 볼 수 있습니다. 나중에 경고를 확인할 것입니다. – Chaniks

+0

@Nav_cfc 나는 주말을 떠날지도 모른다. 그래서 나는 내가 제안한 최종 코드를 게시했다. 이러한 경고의 경우 변수 또는 메서드의 범위를 'private', 'protected'또는 'public'으로 선언 할 수 있습니다. 예를 들면 다음과 같습니다 :'protected var xmlLoader : URLLoader = new URLLoader();'ActionScript 3에서는 모든 변수와 메소드의 범위를 지정하는 것이 좋습니다. – Chaniks