zoukankan      html  css  js  c++  java
  • Flex4 Application中与Module通信

    最近忙于公司项目开发的事情,好一段时间没写Blog了,

    其中有使用到Flex4在项目开发当中,于是分享一,

    Application中与Module通信, 以登录为例
     

    思路:

    1. 编写接口IUserEntry:继承IEventDispatcher,并加入,设置和返回 用户名方法名;

    2.新建Module,实现IUserEntry 接口,并新建 登录事件,并颁发登录事件绑定;

    3.在Application中,创建并使用接口和实例;

    主要代码:

    //IUserEntry.as 接口
    package com.oreilly.f4cb
    {
        import flash.events.IEventDispatcher;
        public interface IUserEntry extends IEventDispatcher
        {
            function getFullName():String;
            function get firstName():String;
            function set firstName( str:String ):void;
            function get lastName():String;
            function set lastName( str:String ):void;
        }
    }
    //myModule.mxml

    <mx:Module implements="com.oreilly.f4cb.IUserEntry"
               xmlns:fx
    ="http://ns.adobe.com/mxml/2009"
               xmlns:s
    ="library://ns.adobe.com/flex/spark"
               xmlns:mx
    ="library://ns.adobe.com/flex/mx"
               layout
    ="vertical" width="100%" height="100%">
        
    <fx:Metadata>
            [Event(name="submit", type="flash.events.Event")]
        
    </fx:Metadata>
         
    <fx:Script>
            
    <![CDATA[
                private var _firstName:String;
                private var _lastName:String;
                private function handleSubmit():void
                {
                    firstName = firstNameInput.text;
                    lastName = lastNameInput.text;
                    dispatchEvent( new Event( "submit" ) );
                }
                public function getFullName():String
                {
                    return _lastName + ", " + _firstName;
                }
                [Bindable]
                public function get firstName():String
                {
                    return _firstName;
                }
                public function set firstName( value:String ):void
                {
                    _firstName = value;
                }
                [Bindable]
                public function get lastName():String
                {
                    return _lastName;
                }
                public function set lastName( value:String ):void
                {
                    _lastName = value;
                }
            
    ]]>
       
    </fx:Script>
        
    <s:HGroup verticalAlign="bottom">
            
    <s:Label text="First Name:" />
            
    <s:TextInput id="firstNameInput" width="100%" />
        
    </s:HGroup>
        
    <s:HGroup verticalAlign="bottom">
            
    <s:Label text="Last Name:" />
            
    <s:TextInput id="lastNameInput" width="100%" />
        
    </s:HGroup>
        
    <s:Button label="submit" click="handleSubmit();" />
    </mx:Module>

    //ComunicationWithModule.mxml

    <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">
        
    <fx:Script>
            
    <![CDATA[
                import com.oreilly.f4cb.IUserEntry;
                private var myModule:IUserEntry;
                private function handleModuleReady():void
                {
                    myModule = moduleLoader.child as IUserEntry;
                    myModule.addEventListener( "submit", handleSubmit );
                }
                private function handleSubmit( evt:Event ):void
                {
                    welcomeField.text = "Hello " + myModule.getFullName();
                }
                public function getInformation():String
                {
                    return "Greetings!";
                }
            
    ]]>
        
    </fx:Script>
  • 相关阅读:
    [哈工大操作系统]一、环境配置
    [算法笔记]带权并查集
    C++:Reference to non-static member function must be called
    [算法笔记]并查集
    C++:string.size()比较问题
    [算法笔记]二分总结
    【LeetCode每日一题】2020.10.15 116. 填充每个节点的下一个右侧节点指针
    1Manjaro的安装
    【《你不知道的JS(中卷②)》】一、 异步:现在与未来
    【LeetCode每日一题】2020.7.14 120. 三角形最小路径和
  • 原文地址:https://www.cnblogs.com/dzone/p/2097039.html
Copyright © 2011-2022 走看看