2013-02-03 6 views
0

Flex 모바일 앱에서 Google+와 Facebook을 포함한 5 가지 소셜 네트워크를 통해 OAuth 로그인을 처리하는 5 View입니다. View의 상기 메뉴를 통해 선택되는 아래와 :Flex mxml 파일을 사용한 상속 - 스크린 샷 첨부

파일명

enter image description here가 FB.mxml, GG.mxml, MR.mxml, OK.mxml, VK.mxml 그들의 소스 코드 을 보이는 매우있다 비슷한 :

<?xml version="1.0" encoding="utf-8"?> 
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     viewActivate="loadInfo(event)" 
     viewDeactivate="closeSWV(event)" 
     title="Facebook.com"> 
.... 
      private function closeSWV(event:Event=null):void { 
       _busy.visible = _busy.includeInLayout = false; 
       _reload.visible = _reload.includeInLayout = true; 

       stage.removeEventListener(Event.RESIZE, resizeSWV); 
       if (! _swv) 
        return; 
       _swv.removeEventListener(Event.COMPLETE, extractAccessToken); 
       _swv.removeEventListener(LocationChangeEvent.LOCATION_CHANGE, extractAccessToken); 
       _swv.removeEventListener(IOErrorEvent.IO_ERROR, closeSWV); 
       _swv.removeEventListener(ErrorEvent.ERROR, closeSWV); 
       _swv.dispose(); 
       _swv = null; 
      }   

      private function resizeSWV(event:Event=null):void { 
       if (! _swv) 
        return; 
       // align to the right-bottom corner 
       _swv.viewPort = new Rectangle(stage.stageWidth - Preferans.SCALE * width, 
        stage.stageHeight - Preferans.SCALE * height, 
        Preferans.SCALE * width, 
        Preferans.SCALE * height); 
      } 
.... 
     <s:VGroup> 
      <s:Label id="_first" fontWeight="bold" text="Your name:" /> 
      <s:Label id="_gender" fontWeight="bold" text="Gender:" /> 
      <s:Label id="_city" fontWeight="bold" text="City:" /> 
     </s:VGroup> 

    <s:Button id="_play" 
       label="Play" 
       click="startGame(event)" 
       includeInLayout="false" 
       visible="false" /> 
</s:View> 

내 문제는 : 위에 나열된 5 개 MXML 파일은 많은 유사한 방법과 변수와 UI 요소와 단지 몇 가지 방법과 변수를 가지고있다.

mxml 파일 (순수 AS3 클래스와 비교하여)이 간단하지 않기 때문에 여러 번 "기본 클래스"를 여러 번 소개하려고 시도했지만 항상 포기했습니다.

누구나 아이디어를 얻으시겠습니까?이 문제를 어떻게 해결합니까?

답변

3

목록의 각 행에서 사용하려는 UI 구성 요소를 확장하는 추상 클래스를 정의 할 수 있습니다. 귀하의 경우에는 View으로 확장됩니다. 당신이 대신으로 View

<your.package:SocialAccountView 
    xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    viewActivate="loadInfo(event)" 
    viewDeactivate="closeSWV(event)" 
    title="Facebook.com"> 

</your.package:SocialAccountView> 

의 주요 유형으로 생성 된 클래스를 사용할 수 mxml 파일에 그 후

package your.package{ 
    public class SocialAccountView extends View{ 

     // in this class you can add the generic methods 
     // that you want the view to have 

    } 
} 

, 당신이 알고있는 목록의 모든 항목은 해당 유형의 것을 , 그리고 부모 클래스의 메서드를 가지고. 각 뷰에서 메서드를 재정의 할 수도 있습니다.

UI 구성 요소와 관련하여 내가 가질 수있는 최대 추상화 수준은 추가 구성 요소를 작성하여 모든보기에서 사용하는 것입니다. 뭔가 같은 ...

Labels.mxml

<s:VGroup> 
     <s:Label id="_first" fontWeight="bold" text="Your name:" /> 
     <s:Label id="_gender" fontWeight="bold" text="Gender:" /> 
     <s:Label id="_city" fontWeight="bold" text="City:" /> 
    </s:VGroup> 

다음이 도움이

<your.package:Labels 
       id="labelsComponent"/> 

희망처럼 각 구성 요소에서 사용.

+0

고맙겠지 만 _name, _gender, _city와 같은 일반적인 UI 요소를 추가하는 위치 (파일에서) 내 질문에 나열된 레이블은 무엇입니까? –