Flash AS3 文档类中未定义的属性 MouseEvent
这是我第一次尝试在 AS3 中使用文档类,但我很挣扎。 我正在尝试将事件侦听器添加到 2 层深度的影片剪辑中,等待单击,但出现以下错误。
ERROR: Access of undefined property MouseEvent
package
{
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
public class game extends MovieClip
{
public var snd_state = true;
public function game()
{
ui_setup();
}
public function ui_setup()
{
ui_mc.toggleMute_mc.addEventListener(MouseEvent.CLICK, snd_toggle);
}
public function snd_toggle(MouseEvent)
{
// 0 = No Sound, 1 = Full Sound
trace("Toggle");
}
}
}
this is my first time trying to use document classes in AS3 and im struggling.
I am trying to add event listeners to a 2 levels deep movie clip, waiting for a click however i am getting the following error.
ERROR: Access of undefined property MouseEvent
package
{
import flash.display.MovieClip;
import flash.media.Sound;
import flash.media.SoundChannel;
public class game extends MovieClip
{
public var snd_state = true;
public function game()
{
ui_setup();
}
public function ui_setup()
{
ui_mc.toggleMute_mc.addEventListener(MouseEvent.CLICK, snd_toggle);
}
public function snd_toggle(MouseEvent)
{
// 0 = No Sound, 1 = Full Sound
trace("Toggle");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要使用一个类,则需要导入它。编译器告诉您,您已经引用了 MouseEvent 类,但没有将其包含在代码中。我已经为您清理了一些:
您会注意到我在方法末尾添加了
:void
。这表明要返回什么类型的变量。例如,如果您的方法返回一个字符串,则它将是:String
。还向您的 snd_toggle 处理程序添加了一个参数。该参数称为“event”,它是类MouseEvent
(event:MouseEvent
) 的实例。If you're going to use a class, you need to import it. The compiler is telling you that you've referenced the MouseEvent class but didn't include it in your code. I've cleaned it up a bit for you:
You'll note that I added
:void
to the end of your methods. This indicates what type of variable to return. For example, if your method returns a string it would be:String
. Also added a paramter to yoursnd_toggle
handler. The parameter is called "event" and it's an instance of classMouseEvent
(event:MouseEvent
).您必须导入事件:
import flash.events.MouseEvent
函数参数还需要一个名称:
public function snd_toggle(bblabla:MouseEvent) { ...
You must import the event:
import flash.events.MouseEvent
The function parameter also needs a name:
public function snd_toggle(bblabla:MouseEvent) { ...