如何在flex中调度自定义事件

发布于 2024-11-07 01:41:15 字数 1726 浏览 0 评论 0原文

如何

在我的主 mxml 文件中的 Flex 中分派自定义事件 我已将此代码放入 controlmanagerevent 中分派此函数

private var ageVerifyMessage:AgeVerify = new AgeVerify();

public function onAgeVerifyFailed(event:ControlManagerEvent) : void
    {
        ageVerifyMessage.visible = true;
        return;
    }// end function

我已使用此代码

private function getUserDetailsHandler(event:ResultEvent) : void
    {
        userDetails = ResponseParser.parseUserDetails(event.result as Object);
        if (!userDetails || !userDetails.age)
        {
            if (_flashVars.birth_date && _flashVars.birth_date != "" && _flashVars.birth_date.toString().split("/").length == 3)
            {
                reportConnectedUser();
            }
            else
            {
                dispatchEvent(new ControlManagerEvent(ControlManagerEvent.onAgeVerifyFailed));
            }
        }
        else
        {
            reportConnectedUser(userDetails.age);
        }
        return;
    }// end function



private var _controller:IControlManager;


public function initApp() : void
    {
        _controller.addEventListener(ControlManagerEvent.onServerStatusChange, onServerStatusChange);
        _controller.addEventListener(ControlManagerEvent.onSelfCamFailed, onSelfCamFailed);
        _controller.addEventListener(ControlManagerEvent.onNoCamerasFound, onNoCamerasFound);
        _controller.addEventListener(ControlManagerEvent.onAgeVerifyFailed, onAgeVerifyFailed);

_controller.initController();
        return;
    }// end function




<local:AgeVerify horizontalCenter="0" id="ageVerifyMessage1" verticalCenter="0" visible="false"/>

我想问我缺少什么 为什么我的自定义事件不起作用

how to dispatch custom event in flex

in my main mxml file i have put this code to dispatch this function

private var ageVerifyMessage:AgeVerify = new AgeVerify();

public function onAgeVerifyFailed(event:ControlManagerEvent) : void
    {
        ageVerifyMessage.visible = true;
        return;
    }// end function

in controlmanagerevent i have used this code

private function getUserDetailsHandler(event:ResultEvent) : void
    {
        userDetails = ResponseParser.parseUserDetails(event.result as Object);
        if (!userDetails || !userDetails.age)
        {
            if (_flashVars.birth_date && _flashVars.birth_date != "" && _flashVars.birth_date.toString().split("/").length == 3)
            {
                reportConnectedUser();
            }
            else
            {
                dispatchEvent(new ControlManagerEvent(ControlManagerEvent.onAgeVerifyFailed));
            }
        }
        else
        {
            reportConnectedUser(userDetails.age);
        }
        return;
    }// end function



private var _controller:IControlManager;


public function initApp() : void
    {
        _controller.addEventListener(ControlManagerEvent.onServerStatusChange, onServerStatusChange);
        _controller.addEventListener(ControlManagerEvent.onSelfCamFailed, onSelfCamFailed);
        _controller.addEventListener(ControlManagerEvent.onNoCamerasFound, onNoCamerasFound);
        _controller.addEventListener(ControlManagerEvent.onAgeVerifyFailed, onAgeVerifyFailed);

_controller.initController();
        return;
    }// end function




<local:AgeVerify horizontalCenter="0" id="ageVerifyMessage1" verticalCenter="0" visible="false"/>

i want to ask what i am missing why my customevents not working

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

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

发布评论

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

评论(2

甜尕妞 2024-11-14 01:41:15

从您的代码中我可以看到您正在侦听 _controller 的事件,但调度事件的对象不是 _controller 而是 this

From your code I can see you're listening events of _controller but the object which dispatches event isn't _controller but this.

二货你真萌 2024-11-14 01:41:15

似乎 _controller.dispatchEvent(YourEvent) 应该可以工作。

或者,我假设您没有使用像 Parsley 或 Swiz 这样的任何事件框架,您的 _controller 应该是组件树中的根:

Application
    IControlManager(_controller)
        HBox
            YourComponent

当您在 YourComponent 中分派冒泡事件时,您的 _controller 将可以调用相应的侦听器。

Seems _controller.dispatchEvent(YourEvent) should work.

Or, I assume you're not using any event framework like Parsley or Swiz, your _controller should be kind of root in the component tree:

Application
    IControlManager(_controller)
        HBox
            YourComponent

When you dispatch an bubbling event in YourComponent, your _controller will be possible to invoke corresponding listeners.

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