cc.Class({ extends: cc.Component, properties: { }, start : function() { // var SoundName = this.getAudioSourceByName("StartGun"); // this.playSound(SoundName); }, getAudioSourceByName:function(SoundName){ if(this.node.getChildByName(SoundName).getComponent(cc.AudioSource) != null){ var AudioSource = this.node.getChildByName(SoundName).getComponent(cc.AudioSource); return AudioSource; } // else{ // cc.log(this.node.getChildByName(SoundName)); // } }, playSound:function(AudioSource){//播放音频剪辑。 AudioSource.play(); }, stopSound:function(AudioSource){//停止当前音频剪辑。 AudioSource.stop(); }, pauseSound:function(AudioSource){//暂停当前音频剪辑。 AudioSource.pause(); }, resumeSound:function(AudioSource){//恢复播放。 AudioSource.resume(); }, rewindSound:function(AudioSource){//从头开始播放。 AudioSource.rewind(); }, getDurationSound:function(AudioSource){//获取当前音频的长度 AudioSource.getDuration(); } });