0

我正在尝试使用 as3 在 flash cs6 中开发一个简单的拖放字母学习应用程序,其中播放器应该拖动每个字母并将其按正确的顺序放置......当播放器单击特定字母时(电影剪辑)应该播放相应的发音(mp3音频)......我可以将音频剪辑分配给只有一个字母电影剪辑..但是当我尝试为每个其他字母实现相同的时候我没有这样做..我的代码运行如下....有人可以告诉我如何为每个字母分配不同的音频文件,以便当播放器单击该字母“电影剪辑”时播放该字母的发音音频剪辑...。

import flash.events.MouseEvent;
import flash.display.MovieClip;

var alphabets:Array = new Array(a1, a2, a3, a4);

var sound1:Letter1 = new Letter1();
a1:addEventListener(MouseEvent.CLICK, play1);
function play1(e:MouseEvent):void
{  sound1.play(); }

alphabets:addEventListener(MouseEvent.MOUSE_DOWN, dragMe);

function dragMe(e:MouseEvent):void
{  e.target.startDrag(); }

alphabets:addEventListener(MouseEvent.MOUSE_UP, dropMe);

function dropMe(e:MouseEvent):void
{  e.target.stopDrag(); }
4

1 回答 1

1

您可能应该创建一个简单的类SpeakingLetter来扩展MovieClip(或Sprite)并向其添加声音属性。之后,您将不同的声音分配给不同的 MovieClip,并将您的 MouseEvent.CLICK 事件侦听器添加到您拥有的每个 SpeakingLetter 对象。它会是这样的:

// SpeakingLetter class
package  
{
    import flash.display.MovieClip;

    public class SpeakingLetter extends MovieClip 
    {
        private var _sound:MySound;

        public function SpeakingLetter(inputSound:MySound) 
        {
            super();
            _sound = inputSound;
        }

        public function playSound():void
        {
            _sound.play();
        }   
    }
}

你的主要代码将是这样的

//MAIN CODE
import flash.events.MouseEvent;
import flash.display.MovieClip;

//You should replace these values with your own - I don't know how you store your sounds
const speakingLetterSounds:Array = [new MySound("sound1"), new MySound("sound2"), new MySound("sound3")];

var speakingLetters:Array = [];
var numOfLetters:uint = 3;
for (var i:int = 0; i < numOfLetters; i++)
{
    var currentLeter:SpeakingLetter = new SpeakingLetter(speakingLetterSounds[i]);
    currentLeter.addEventListener(MouseEvent.CLICK, playLetterSound);
    speakingLetters.push(currentLeter);
}

function playLetterSound(e:MouseEvent):void
{
    var currentLetter:SpeakingLetter = e.target as SpeakingLetter;
    currentLetter.playSound();
}

所以你应该只播放按下字母的声音,这样就不会弄乱了。

于 2013-10-02T06:47:15.703 回答