Слушатели событий не стреляют в этот код, кто-нибудь может вести? - PullRequest
0 голосов
/ 15 мая 2011

слушатели событий, не запускающие этот код, могут подсказать мне, что является проблемой с этим кодом

<?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 ]

1 голос
/ 15 мая 2011

Во-первых, количественно определите, что означает "не работает".Вы получаете ошибки компилятора?Или ошибки во время выполнения?Или слушатели событий не стреляют?Или что-то еще происходит?

Во-вторых, такие строки:

 this.parent.addEventListener

Разрыв инкапсуляции.Ребенок не должен ничего знать о своем родителе.Это повсеместно считается плохой практикой.

Ваше использование анонимных функций странно в моих путешествиях по разработке, но я считаю, что это действительно так.Вы установили точки останова внутри функций, чтобы убедиться, что они выполняются?

0 голосов
/ 15 мая 2011

Я вижу, что все ваши слушатели событий устанавливаются внутри initComponent (), поэтому поместите туда команду trace, чтобы убедиться, что вызывается метод. Мы не знаем, все ли настроено вокруг вашего mxml-файла для вызова вашего метода init.

Между прочим, когда я искал "addEventListener" в вашем коде, я сразу увидел, что возникла проблема с использованием таймеров и setTimeout; обратитесь сюда: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setTimeout%28%29

Это не должно вызывать каких-либо поломок, но это глупый бит в вашем коде, поэтому я думаю, что есть много маленьких ошибок, и вам нужно более полно понять, что делает весь ваш код.

...