开发者

event listeners not firing in this code can anybody guide?

event listeners not firing in this code can anybody guide me what is problem with this code

<?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>
                <开发者_如何学C;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>


First, quantify what "not working means". Are you getting compiler errors? Or runtime errors? Or are event listeners not firing? Or is there something else going on?

Second, lines like this:

 this.parent.addEventListener

Break encapsulation. A child should not know anything about it's parent. This would universally be considered a bad practice.

Your use on anonymous functions is odd in my development travels, but I believe it is valid. Have you set breakpoints inside the functions to be sure that they are executing?


I can see that all of your event listeners are being set inside initComponent() so put a trace statement in there to make sure that method is being called. We have no idea if everything is setup surrounding your mxml file to call your init method.

Incidentally, when I searched for "addEventListener" in your code I immediately saw there was an issue with how you are using timers and setTimeout; refer here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setTimeout%28%29

That shouldn't cause anything to break but it's a goofy bit in your code, so I'm thinking there are lots of little errors and you need to more fully understand what all of your code is doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜