在此代码中事件侦听器未触发任何人都可以指导吗?
事件侦听器未在此代码中触发任何人都可以指导我此代码有什么问题吗
<?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>
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>
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,量化“不工作”的含义。您遇到编译器错误吗?或者运行时错误?或者事件侦听器没有触发?还是还有其他事情发生?
其次,像这样的行:
打破封装。孩子不应该知道关于其父母的任何事情。这通常被认为是一种不好的做法。
在我的开发之旅中,您对匿名函数的使用很奇怪,但我相信它是有效的。您是否在函数内设置了断点以确保它们正在执行?
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:
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?
我可以看到所有事件侦听器都在 initComponent() 内设置,因此在其中放置一条跟踪语句以确保正在调用该方法。我们不知道您的 mxml 文件是否已设置好所有内容以调用您的 init 方法。
顺便说一句,当我在您的代码中搜索“addEventListener”时,我立即发现您如何使用计时器和 setTimeout 存在问题;参考这里:
http://help .adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#setTimeout%28%29
这不应该导致任何破坏,但它在您的代码中有点愚蠢,所以我认为存在很多小错误,您需要更全面地了解所有代码的用途。
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.