Actionscript 3 继承Flex mxml文件-附屏幕截图

Actionscript 3 继承Flex mxml文件-附屏幕截图,actionscript-3,apache-flex,flex4,flex4.6,flex-mobile,Actionscript 3,Apache Flex,Flex4,Flex4.6,Flex Mobile,在一个Flex移动应用程序中,我有5个s,通过5个不同的社交网络(包括Google+和Facebook)处理OAuth登录。正在通过如下所示的菜单选择视图s: 文件名为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" xmln

在一个Flex移动应用程序中,我有5个s,通过5个不同的社交网络(包括Google+和Facebook)处理OAuth登录。正在通过如下所示的菜单选择
视图
s:

文件名为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>

....
私有函数closeSWV(事件:event=null):无效{
_busy.visible=\u busy.includeInLayout=false;
_reload.visible=\u reload.includeInLayout=true;
stage.removeEventListener(Event.RESIZE,resizeSWV);
如果(!\u swv)
返回;
_swv.removeEventListener(Event.COMPLETE,extractAccessToken);
_swv.removeEventListener(LocationChangeEvent.LOCATION\u CHANGE,extractAccessToken);
_swv.removeEventListener(IOErrorEvent.IO_ERROR,closeSWV);
_swv.removeEventListener(ErrorEvent.ERROR,closeSWV);
_swv.dispose();
_swv=null;
}           
私有函数resizeSWV(事件:event=null):void{
如果(!\u swv)
返回;
//与右下角对齐
_swv.viewPort=新矩形(stage.stageWidth-Preferans.SCALE*宽度,
stage.stageHeight-首选项。比例*高度,
首选。比例*宽度,
首选(比例*高度);
}
....
我的问题是:上面列出的5个mxml文件有许多类似的方法和变量以及UI元素,只有少数不同的方法和变量

我已经多次尝试为它们引入“基类”,但总是放弃,因为对于mxml文件(与纯AS3类相比)来说,这并不简单


有人知道如何处理这个问题吗?

您可以定义一个抽象类来扩展要在列表的每一行中使用的UI组件。在您的情况下,它将扩展
视图

package your.package{
    public class SocialAccountView extends View{

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

    }
}
之后,在
mxml
文件中,可以使用创建的类作为主类型,而不是
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>

这样您就知道列表中的所有项都属于该类型,并且具有父类的方法。您甚至可以覆盖每个视图中的方法

关于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"/>


希望这能有所帮助。

您可以定义一个抽象类来扩展要在列表的每一行中使用的UI组件。在您的情况下,它将扩展
视图

package your.package{
    public class SocialAccountView extends View{

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

    }
}
之后,在
mxml
文件中,可以使用创建的类作为主类型,而不是
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>

这样您就知道列表中的所有项都属于该类型,并且具有父类的方法。您甚至可以覆盖每个视图中的方法

关于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"/>

希望这能有所帮助。

谢谢,但在哪里(在哪个文件中)添加常见的UI元素-如我的问题中列出的_name、_gender、_city标签?谢谢,但在哪里(在哪个文件中)添加常见的UI元素-如我的问题中列出的_name、_gender、_city标签?