事件监听器没有在此代码中触发可以任何人指导?

时间:2011-05-15 11:47:47

标签: flex flex3 flex4 flexbuilder

事件监听器未在此代码中触发,任何人都可以指导我这段代码的问题

<?xml version="1.0" encoding="UTF-8"?>
<mx:HBox creationComplete="{initComponent();}" height="51" rollOut="{isOnControl = false;setTimer(true);}" rollOver="{isOnControl = true;setTimer(false);}" backgroundImage="C:\Users\sidd\Desktop\5\bandoochat\Image\image 83.png" verticalAlign="middle" xmlns:mx="http://www.adobe.com/2006/mxml" width="240">
    <mx:Script><![CDATA[
        import assets.EmbeddedAssets_menuRadioIcon;

        import com.myproj.classes.*;
        import com.myproj.events.*;
        import com.myproj.interfaces.*;

        import flash.events.*;
        import flash.utils.*;

        import mx.binding.*;
        import mx.collections.*;
        import mx.containers.*;
        import mx.controls.*;
        import mx.core.*;
        import mx.effects.*;
        import mx.events.*;
        import mx.styles.*;


        [Binding]
        private var toolbarTimer:Timer;
        private var toolbarAnimationPlaying:Boolean = false;
        private var audioDevices:ArrayCollection;
        private var cameraCollection:Array;
        private var isOnMenu:Boolean = false;
        private var cameraDevices:ArrayCollection;
        private var audioCollection:Array;
        private var _controller:IControlManager;
        private var toolbarMoveEffect:Fade;
        private var cameraChoose:PopUpButton;
        private var cameraDevicesMenu:Menu;
        private var audioDevicesMenu:Menu;
        private var isOnControl:Boolean = false;

        public function resetToolbarTimer(event:MouseEvent = null) : void
        {
            setTimer(false);
            setTimer(true);
            if (!toolbarAnimationPlaying)
            {
                toolbarAnimationPlaying = true;
                setToolbarState(true);
            }
            return;
        }// end function


        public function setTimer(param1:Boolean) : void
        {
            if (this.includeInLayout)
            {
                if (!param1)
                {
                    toolbarTimer.stop();
                    toolbarTimer.reset();
                }
                else
                {
                    toolbarTimer.reset();
                    toolbarTimer.start();
                }
            }
            return;
        }// end function


        public function videoSelectedHandler(event:MenuEvent) : void
        {
            var i:int = 0;
            while (i < cameraDevices.length)
            {

                cameraDevices.getItemAt(i).icon = null;
                i++;
            }
            event.item.icon = EmbeddedAssets_menuRadioIcon;
            _controller.setNewCamDevice(event.index);
            return;
        }// end function


        public function muteAudio() : void
        {
            _controller.muteAudio();
            return;
        }// end function


        public function initComponent() : void
        {
            toolbarTimer.addEventListener(TimerEvent.TIMER, toolbarTimerHandler);
            this.parent.addEventListener(MouseEvent.MOUSE_MOVE, resetToolbarTimer);
            this.parent.addEventListener(MouseEvent.ROLL_OUT, function () : void
            {
                setTimeout(toolbarTimerHandler, 200);
                return;
            }// end function
            );
            _controller.addEventListener(ControlManagerEvent.onNoCamerasFound, onNoCamerasFound);
            audioCollection = _controller.microphones;
            var i:int;
            while (i < audioCollection.length)
            {

                audioDevices.addItem({label:audioCollection[i], icon:i == 0 ? (EmbeddedAssets_menuRadioIcon) : (null)});
                i = (i + 1);
            }
            audioDevicesMenu = Menu.createMenu(this, audioDevices);
            audioDevicesMenu.addEventListener(MouseEvent.MOUSE_OVER, function () : void
            {
                isOnMenu = true;
                return;
            }// end function
            );
            audioDevicesMenu.addEventListener(MouseEvent.MOUSE_OUT, function () : void
            {
                isOnMenu = false;
                return;
            }// end function
            );
            audioDevicesMenu.addEventListener(MenuEvent.ITEM_CLICK, audioSelectedHandler);
            audioDevicesMenu.width = 200;
            cameraCollection = _controller.cameras;
            var j:int;
            while (j < cameraCollection.length)
            {

                cameraDevices.addItem({label:cameraCollection[j], icon:j == 0 ? (EmbeddedAssets_menuRadioIcon) : (null)});
                j = (j + 1);
            }
            cameraDevicesMenu = Menu.createMenu(this, cameraDevices);
            cameraDevicesMenu.addEventListener(MouseEvent.MOUSE_OVER, function () : void
            {
                isOnMenu = true;
                return;
            }// end function
            );
            cameraDevicesMenu.addEventListener(MouseEvent.MOUSE_OUT, function () : void
            {
                isOnMenu = false;
                return;
            }// end function
            );
            cameraDevicesMenu.addEventListener(MenuEvent.ITEM_CLICK, videoSelectedHandler);
            cameraDevicesMenu.width = 200;
            return;
        }// end function


        public function onNoCamerasFound(event:ControlManagerEvent) : void
        {
            this.includeInLayout = false;
            this.visible = false;
            return;
        }// end function


        public function setToolbarState(param1:Boolean) : void
        {
            if (this.includeInLayout)
            {
                if (!isOnControl)
                {
                    if (toolbarMoveEffect.isPlaying)
                    {
                        toolbarMoveEffect.reverse();
                        return;
                    }
                    toolbarMoveEffect.alphaFrom = !param1 ? (1) : (0);
                    toolbarMoveEffect.alphaTo = param1 ? (1) : (0);
                    toolbarMoveEffect.play();
                }
            }
            return;
        }// end function


        public function toolbarTimerHandler(event:Event = null) : void
        {
            if (!isOnMenu)
            {
                audioDevicesMenu.hide();
                cameraDevicesMenu.hide();
                toolbarAnimationPlaying = false;
                setTimer(false);
                setToolbarState(false);
            }
            return;
        }// end function


        public function muteVideo() : void
        {
            _controller.muteVideo();
            return;
        }// end function



        public function _LocalCameraControls_Fade1_i() : Fade
        {
            var fade:* = new Fade();
            toolbarMoveEffect = fade;
            fade.duration = 220;
            BindingManager.executeBindings(this, "toolbarMoveEffect", toolbarMoveEffect);
            return  fade;
        }// end function


        public function audioSelectedHandler(event:MenuEvent) : void
        {
            var i:int = 0;
            while (i < audioDevices.length)
            {

                audioDevices.getItemAt(i).icon = null;
                i++;
            }
            event.item.icon = EmbeddedAssets_menuRadioIcon;
            _controller.setNewMicDevice(event.index);
            return;
        }// end function

    ]]></mx:Script>

    <mx:HBox horizontalGap="1" paddingTop="12" verticalAlign="middle" width="100%">
        <mx:Canvas>
            <mx:PopUpButton id="audioChoose"    popUpStyleName="popupStyle" visible="true"/>
            <mx:Image click="{muteAudio();}" id="camMicIcon"  toolTip="Mute Mic" source="C:\Users\sidd\Desktop\5\bandoochat\Image\image 63.png"/>
        </mx:Canvas>
        <mx:Image click="{audioChoose.open();}" id="camAudioSelector1"  toolTip="Select audio device" source="C:\Users\sidd\Desktop\5\bandoochat\Image\image 104.png"/>
        <mx:Spacer width="100%"/>
        <mx:HBox horizontalGap="1">
            <mx:Canvas>
                <mx:PopUpButton id="cameraChoose1"    popUpStyleName="popupStyle" />
                <mx:Image click="{muteVideo();}" id="camVideoIcon"  toolTip="Turn Camera OFF" source="C:\Users\sidd\Desktop\5\bandoochat\Image\image 56.png"/>
            </mx:Canvas>
            <mx:Image click="{cameraChoose.open();}" id="camVideoSelector1"  toolTip="Select video device" source="C:\Users\sidd\Desktop\5\bandoochat\Image\image 104.png"/>
        </mx:HBox>
    </mx:HBox>
</mx:HBox>

2 个答案:

答案 0 :(得分:1)

首先,量化“不工作的意思”。你收到编译错误了吗?还是运行时错误?或者事件监听器没有解雇?或者还有其他事情发生了吗?

其次,这样的行:

 this.parent.addEventListener

打破封装。一个孩子不应该对它的父母一无所知。这通常被认为是一种不好的做法。

您在匿名函数中的使用在我的开发旅行中很奇怪,但我相信它是有效的。您是否在函数内部设置了断点以确保它们正在执行?

答案 1 :(得分:0)

我可以看到所有的事件侦听器都在initComponent()中设置,因此在其中放置一个trace语句以确保调用该方法。我们不知道是否围绕您的mxml文件设置了所有内容来调用您的init方法。

顺便说一下,当我在你的代码中搜索“addEventListener”时,我立刻就看到了你如何使用timers和setTimeout的问题;请参考: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setTimeout%28%29

这不应该导致任何中断,但它在代码中是一个傻瓜,所以我认为有很多小错误,你需要更全面地了解你的所有代码正在做什么。