将数据从弹出窗口发送到主应用程序。

发布于 2024-11-27 06:34:34 字数 4306 浏览 0 评论 0原文

我没有得到我正在寻找的答案。 我想将收到的请求数据发送到主应用程序。

    <?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"  remove="titlewindow1_removeHandler(event)"
                width="400" height="220" layout="absolute" title="USER LOGIN">
    <mx:Metadata>
        [Event(name="commEvent", type="flash.events.Event")]
    </mx:Metadata>
    <mx:Script>
        <![CDATA[
            import data.Data;

            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;


            [Bindable]
            public var userID:String;

            private function loginUser():void{
                trace("btn");
                var req:URLRequest = new URLRequest('http://localhost/CCN/userProcess.php');
                var loader:URLLoader = new URLLoader();
                req.method="POST";

                var variables:URLVariables = new URLVariables();
                variables.email= username.text;
                variables.password= password.text;
                variables.action= "login_user";
                req.data=variables;

                loader.addEventListener(Event.COMPLETE,onDataLoaded);
                loader.load(req);
            }
            protected function loginButton_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub

                loginUser();
            }


            private function onDataLoaded(e:Event):void{
                var xml:XML= new XML(e.target.data);
                if(xml.status=="success"){

                //SEND DATA TO MAIN APPLICATION ????
                    PopUpManager.removePopUp(this);

                }else{
                    fail.visible=true;
                    username.text="";
                    password.text="";
                    username.setFocus();
                }


            }

            protected function loginButton_keyDownHandler(ee:KeyboardEvent):void
            {
                // TODO Auto-generated method stub
                if(ee.keyCode==13){
                    loginUser();
                }
            }

            protected function titlewindow1_removeHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub

            }

        ]]>
    </mx:Script>

    <mx:TextInput id="username" x="141" y="31" width="199" text=""/>
    <mx:TextInput keyDown="loginButton_keyDownHandler(event)" text="000" id="" x="141" y="84" width="199" displayAsPassword="true"/>
    <mx:Button id="loginButton" x="275" y="133" label="LOGIN" click="loginButton_clickHandler(event)"/>
    <mx:Label x="22" y="33" text="Email"/>
    <mx:Label x="22" y="86" text="Password"/>
    <mx:Label x="22" visible="false" y="135" id="fail" color="#FF0000" text="LOGIN FAILED"/>
</mx:TitleWindow>

这是主要的应用程序代码

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                minWidth="955" minHeight="600" backgroundColor="#FFFFFF"
                creationComplete="application1_creationCompleteHandler(event)" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.containers.TitleWindow;
            import mx.core.IFlexDisplayObject;
            import mx.events.CloseEvent;
            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;

            //private var loginWindow:TitleWindow;
            public var user:String;
            private var login:Login

            private function application1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                login = Login(
                    PopUpManager.createPopUp(this, Login, true));
                PopUpManager.centerPopUp(login);


                //login['loginButton'].addEventListener(MouseEvent.CLICK,onClose);
                login.addEventListener(CloseEvent.CLOSE,oncc)

            }
            private function onClose(e:Event):void{
                trace("Trace : "+login.userID);
            }
            private function


        ]]>
    </mx:Script>
</mx:Application>

I'm not getting the answer I'm looking for.
I want to send the request data i get to the main application.

    <?xml version="1.0" encoding="utf-8"?>
<mx:TitleWindow xmlns:mx="http://www.adobe.com/2006/mxml"  remove="titlewindow1_removeHandler(event)"
                width="400" height="220" layout="absolute" title="USER LOGIN">
    <mx:Metadata>
        [Event(name="commEvent", type="flash.events.Event")]
    </mx:Metadata>
    <mx:Script>
        <![CDATA[
            import data.Data;

            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;


            [Bindable]
            public var userID:String;

            private function loginUser():void{
                trace("btn");
                var req:URLRequest = new URLRequest('http://localhost/CCN/userProcess.php');
                var loader:URLLoader = new URLLoader();
                req.method="POST";

                var variables:URLVariables = new URLVariables();
                variables.email= username.text;
                variables.password= password.text;
                variables.action= "login_user";
                req.data=variables;

                loader.addEventListener(Event.COMPLETE,onDataLoaded);
                loader.load(req);
            }
            protected function loginButton_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub

                loginUser();
            }


            private function onDataLoaded(e:Event):void{
                var xml:XML= new XML(e.target.data);
                if(xml.status=="success"){

                //SEND DATA TO MAIN APPLICATION ????
                    PopUpManager.removePopUp(this);

                }else{
                    fail.visible=true;
                    username.text="";
                    password.text="";
                    username.setFocus();
                }


            }

            protected function loginButton_keyDownHandler(ee:KeyboardEvent):void
            {
                // TODO Auto-generated method stub
                if(ee.keyCode==13){
                    loginUser();
                }
            }

            protected function titlewindow1_removeHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub

            }

        ]]>
    </mx:Script>

    <mx:TextInput id="username" x="141" y="31" width="199" text=""/>
    <mx:TextInput keyDown="loginButton_keyDownHandler(event)" text="000" id="" x="141" y="84" width="199" displayAsPassword="true"/>
    <mx:Button id="loginButton" x="275" y="133" label="LOGIN" click="loginButton_clickHandler(event)"/>
    <mx:Label x="22" y="33" text="Email"/>
    <mx:Label x="22" y="86" text="Password"/>
    <mx:Label x="22" visible="false" y="135" id="fail" color="#FF0000" text="LOGIN FAILED"/>
</mx:TitleWindow>

here is the main application code

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                minWidth="955" minHeight="600" backgroundColor="#FFFFFF"
                creationComplete="application1_creationCompleteHandler(event)" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.containers.TitleWindow;
            import mx.core.IFlexDisplayObject;
            import mx.events.CloseEvent;
            import mx.events.FlexEvent;
            import mx.managers.PopUpManager;

            //private var loginWindow:TitleWindow;
            public var user:String;
            private var login:Login

            private function application1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                login = Login(
                    PopUpManager.createPopUp(this, Login, true));
                PopUpManager.centerPopUp(login);


                //login['loginButton'].addEventListener(MouseEvent.CLICK,onClose);
                login.addEventListener(CloseEvent.CLOSE,oncc)

            }
            private function onClose(e:Event):void{
                trace("Trace : "+login.userID);
            }
            private function


        ]]>
    </mx:Script>
</mx:Application>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走过海棠暮 2024-12-04 06:34:34

我建议通过添加自定义事件来解决此问题,因为您的标签暗示您可能会理解。

如果没有,请按照以下步骤操作。

1) 创建一个新的事件类型(在actionscript 中扩展事件类 - 确保覆盖clone())

2) 在弹出窗口的父应用程序中为新事件类型添加一个事件侦听器

3) 使弹出窗口分派您的新事件关闭之前的事件类型

4) 在事件处理程序中处理您要查找的任何内容(用户 ID?)。

我建议将 userID 附加到实际事件,这样父级就不会直接寻址 login.userID。从松耦合的角度来看,它更正确。也就是说,如果您不愿意,您可以通过不附加用户 ID 来简化解决方案。松耦合是一个伟大的目标,但如果您只打算使用这种关系一次,那么它并不是非常必要的。

如果您选择采用更紧密的耦合路线,那么您只需分派具有自定义“类型”的事件,而不是扩展事件。

如果您需要较低级别的示例(更少的描述,更多的代码),请告诉我,我也可以提供帮助。

下面提供的示例是稍微复杂的版本,您可以在其中扩展事件以包含数据。

事件类::

package mycomponents
{
    import flash.events.Event;
    public class CustomEvent extends Event
    {
        public static const EVENT_TYPE_NAME:String = "myEventType"

        public var mUserID:String = "";
        public var mSuccess:Boolean = false;

        public function CustomEvent(aType:String, aUserID:String, aSuccess:Boolean)
        {
            super(aType)
            mUserID = aUserID;
            mSuccess = aSuccess;
        }

        override public function clone():Event
        {
            var lEvent:CustomEvent = new CustomEvent(mUserID, mSuccess);
            return lEvent;
        }
    }
}

在 Popup::

private var loginSuccessful:Boolean = false;

private function onDataLoaded(e:Event):void{
    var xml:XML= new XML(e.target.data);
    if(xml.status=="success"){

        userID = username.text;
        loginSuccessful = true;             
        //SEND DATA TO MAIN APPLICATION
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME, userID, loginSuccessful );
        PopUpManager.removePopUp(this);

    }else{
        fail.visible=true;
        username.text="";
        password.text="";
        username.setFocus();
    }           
}

protected function titlewindow1_removeHandler(event:FlexEvent):void
{          
    if (!loginSuccessful)
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME," userID, loginSuccessful ));
} 

和主应用程序中::

import mycomponents.CustomEvent;

private function application1_creationCompleteHandler(event:FlexEvent):void 
{
    //...your code
    login.addEventListener(CustomEvent.EVENT_TYPE_NAME, handleLoginEvent);
}

private function handleLoginEvent(aEvent:CustomEvent)
{
    //My example code dispatches an event with mSuccess = false if the login prompt closes
    //without a successful login
    //
    //now do whatever you want with the information from the popup
    //aEvent.mUserID gets you ID
    //aEvent.mSuccess gets you success

}

在工作休息期间将其放在一起,因此没有 Promise 会按原样编译。

I would recommend solving this by adding a custom event, as your tag implies you may understand.

If not, here are the steps you would follow.

1) Create a new Event type (extend the Event class in actionscript - be sure to override clone())

2) Add an event listener for your new Event type in the parent application on the popup

3) cause the popup to dispatch your new Event type before it closes

4) Handle whatever it is you're looking for (userID?) in the event handler.

I would recommend attaching the userID to the actual event, so that the parent is not directly addressing login.userID. From a loose coupling standpoint, it's more correct. That said, if you don't wish to, you can simplify the solution by NOT attaching the userID. Loose coupling is a great goal, but if you only plan to use this relationship once, it's not incredibly necessary.

If you choose to go the tighter coupling route, then you only have to dispatch an event with a custom "type" instead of an extended Event.

If you need a lower level example (less description, more code) let me know, and I can help with that as well.

The example provided below is the slightly more complex version, where you extend an event to contain the data.

Event class::

package mycomponents
{
    import flash.events.Event;
    public class CustomEvent extends Event
    {
        public static const EVENT_TYPE_NAME:String = "myEventType"

        public var mUserID:String = "";
        public var mSuccess:Boolean = false;

        public function CustomEvent(aType:String, aUserID:String, aSuccess:Boolean)
        {
            super(aType)
            mUserID = aUserID;
            mSuccess = aSuccess;
        }

        override public function clone():Event
        {
            var lEvent:CustomEvent = new CustomEvent(mUserID, mSuccess);
            return lEvent;
        }
    }
}

In Popup::

private var loginSuccessful:Boolean = false;

private function onDataLoaded(e:Event):void{
    var xml:XML= new XML(e.target.data);
    if(xml.status=="success"){

        userID = username.text;
        loginSuccessful = true;             
        //SEND DATA TO MAIN APPLICATION
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME, userID, loginSuccessful );
        PopUpManager.removePopUp(this);

    }else{
        fail.visible=true;
        username.text="";
        password.text="";
        username.setFocus();
    }           
}

protected function titlewindow1_removeHandler(event:FlexEvent):void
{          
    if (!loginSuccessful)
        dispatchEvent(new CustomEvent(CustomEvent.EVENT_TYPE_NAME," userID, loginSuccessful ));
} 

And in the Main Application::

import mycomponents.CustomEvent;

private function application1_creationCompleteHandler(event:FlexEvent):void 
{
    //...your code
    login.addEventListener(CustomEvent.EVENT_TYPE_NAME, handleLoginEvent);
}

private function handleLoginEvent(aEvent:CustomEvent)
{
    //My example code dispatches an event with mSuccess = false if the login prompt closes
    //without a successful login
    //
    //now do whatever you want with the information from the popup
    //aEvent.mUserID gets you ID
    //aEvent.mSuccess gets you success

}

Tossed that together in the middle of a break at work, so no promises will compile as-is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文