在Actionscript上播放声音

编程入门 行业动态 更新时间:2024-10-24 13:26:06
本文介绍了在Actionscript上播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简单的拖放游戏,开始时是Flash,并且大多数情况下都能正常工作.

I have a simple drag and drop game started in flash and mostly working.

我添加了我的动物,您可以将它们拖放到正确的位置.我还添加了声音,以便当将动物放置在正确的位置时,这是可行的,但是每次我向该动物中添加新的动物时它会播放该声音以及最后一个动物的声音.

I have added my animals and you can drag and drop them in the right place.I have also added sound so that when the animal is dropped in the right spot , that is working however each time I add a new animal to the right spot it plays that sound and the last animal sound as well.

例如.将猪放到猪的空间里,播放猪的声音 将牛放在牛的空间中,播放牛声和猪声 将鸭子放到鸭子空间中,播放鸭子声,牛声和猪声.

e.g. place pig in pig space , it plays pig sound place cow in cow space , it plays cow sound and pig sound place duck in duck space , it plays duck sound and cow sound and pig sound.

很明显,我只想在将动物放置在正确的位置时播放声音-放下(也不要放下一只动物)

Obviously I only want to play the sound when the animal is placed in the right place - on drop ( not on next animal drop also )

我不确定自己做错了什么

I'm not sure what I have done wrong

/*拖放 使指定的符号实例可通过拖放移动. */

/* Drag and Drop Makes the specified symbol instance moveable with drag and drop. */

import flash.media.Sound; var offset:int = 10; var pigStartX:int = 196.80; var pigStartY:int = 292.10; var pigEndX:int = 578.40; var pigEndY:int = 208.50; Pig.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag); function fl_ClickToDrag(event:MouseEvent):void { Pig.startDrag(); } stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); function fl_ReleaseToDrop(event:MouseEvent):void { Pig.stopDrag(); // dragging and dropping the pieces while checking for correct location if(Pig.x < pigEndX - offset || Pig.x > pigEndX + offset || Pig.y < pigEndY - offset ||Pig.y > pigEndY + offset){ Pig.x = pigStartX; Pig.y = pigStartY; } else{ //set piece back to original position Pig.x = pigEndX; Pig.y = pigEndY; var oink:PigOink = new PigOink(); var channel:SoundChannel = oink.play(); //checkGame(); } }

/*拖放 使指定的符号实例可通过拖放移动. */

/* Drag and Drop Makes the specified symbol instance moveable with drag and drop. */

var cowStartX:int = 324; var cowStartY:int = 317.95; var cowEndX:int = 411.50; var cowEndY:int = 140.95; Cow.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2); function fl_ClickToDrag_2(event:MouseEvent):void { Cow.startDrag(); } stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2); function fl_ReleaseToDrop_2(event:MouseEvent):void { Cow.stopDrag(); // dragging and dropping the pieces while checking for correct location if(Cow.x < cowEndX - offset || Cow.x > cowEndX + offset || Cow.y < cowEndY - offset ||Cow.y > cowEndY + offset){ Cow.x = cowStartX; Cow.y = cowStartY; } else{ //set piece back to original position Cow.x = cowEndX; Cow.y = cowEndY; var moo:CowMoo = new CowMoo(); var channel:SoundChannel = moo.play(); //checkGame(); } }

/*拖放 使指定的符号实例可通过拖放移动. */

/* Drag and Drop Makes the specified symbol instance moveable with drag and drop. */

var duckStartX:int = 209.45; var duckStartY:int = 402.05; var duckEndX:int = 56.45; var duckEndY:int = 225.05; Duck.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_3); function fl_ClickToDrag_3(event:MouseEvent):void { Duck.startDrag(); } stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_3); function fl_ReleaseToDrop_3(event:MouseEvent):void { Duck.stopDrag(); // dragging and dropping the pieces while checking for correct location if(Duck.x < duckEndX - offset || Duck.x > duckEndX + offset || Duck.y < duckEndY - offset ||Duck.y > duckEndY + offset){ //set piece back to original position Duck.x = duckStartX; Duck.y = duckStartY; } else{ Duck.x = duckEndX; Duck.y = duckEndY; var quack:DuckQuack = new DuckQuack(); var channel:SoundChannel = quack.play(); //checkGame(); } }

推荐答案

查看您的MouseUp事件处理程序.

Look at your MouseUp event handlers.

您正在将事件侦听器添加到舞台上.因此,每当舞台听到鼠标上移事件时,它们都会被调用.

You are adding the event listener to the stage. So they are all getting called whenever the stage hears a mouse up event.

将这些侦听器添加到母牛,猪等中,就像对鼠标侦听器所做的一样.

Add those listeners to the cow, pig etc just as you did for the mouse down listeners.

那应该解决.

Pig.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag); function fl_ClickToDrag(event:MouseEvent):void { Pig.startDrag(); } //stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop); // change to this Pig.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);

更多推荐

在Actionscript上播放声音

本文发布于:2023-07-11 12:11:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094011.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   Actionscript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!