-2

我试图使用组件资产中的组合框插入音乐。昨天工作正常,但今天突然停止工作,它给了我这个错误:

TypeError:错误 #1009:无法访问空对象引用的属性或方法。

ArgumentError:错误 #2025:提供的 DisplayObject 必须是调用者的子对象。

每次我单击组合框时都会出现这些错误,奇怪的是昨天它工作正常。这是第一帧的代码:

import flash.events.Event;
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.Event;
import flash.media.SoundTransform;
import flash.events.MouseEvent;

//Declare MUSIC Variables
var musicSelection:Sound;
var musicChannel:SoundChannel;
var musicTrack:String = "music/dearly_beloved.mp3";
var musicVolume:Number=0.2;
/*var isMuted = false;*/


loadMusic();
function loadMusic():void 
{
 //first stop old sound playing
  SoundMixer.stopAll();
  musicSelection = new Sound();
  musicChannel = new SoundChannel();
 //create and load the required soun
 musicSelection.load(new URLRequest(musicTrack));
      //when loaded - play it
      musicSelection.addEventListener(Event.COMPLETE, musicLoaded);
     }

      function musicLoaded(evt:Event):void
     {
      //finished with this listener
      musicSelection.removeEventListener(Event.COMPLETE, musicLoaded);
      //play music
      playMusic();
      }

        function playMusic():void
     {
     //play the random or selected music
     musicChannel = musicSelection.play();
     //setting the volume control property to the music channel
     musicChannel.soundTransform = new SoundTransform(musicVolume, 0);
     //but add this one to make repeats
      musicChannel.addEventListener(Event.SOUND_COMPLETE, playAgain);
   }
   function playAgain(evt:Event):void {
     // remove this listener and repeat
     musicChannel.removeEventListener(Event.SOUND_COMPLETE, playAgain);
     playMusic();
     }

这是第二帧的代码:

import flash.events.Event;
menuBtn.addEventListener(MouseEvent.CLICK, goToMenu)
function goToMenu(evt:Event):void
 {
gotoAndPlay(2);
 }
 // BUTTON EVENT LISTENERS
 musicCombo.addEventListener(Event.CHANGE, updateMusic);
 volumeSL.addEventListener(Event.CHANGE, setSlider);

 //process COMBO BOX changes
 function updateMusic(evt:Event):void
 {
if (musicCombo.selectedItem.data == "none")
{
    //no music is required so stop sound playing
    SoundMixer.stopAll();
}
else
{
    //otherwise load in the selected music
    musicTrack = "music/" + musicCombo.selectedItem.data;
    loadMusic();
}
  }

   function setSlider(evt:Event):void
   {
//identify the button clicked
var mySlider:Object = (evt.target);
//adjusting to volume of the music channel
musicVolume = mySlider.value;
musicChannel.soundTransform = new SoundTransform(musicVolume, 0);
    }

每当我单击组合框并且尝试插入另一个组合框而不放置任何数据时都会发生错误,也会发生相同的错误。希望你们能尽快帮助我,因为这是本周星期五到期的 xD

谢谢

4

1 回答 1

0

好吧,找到答案了。看来我需要输入这 3 行代码:

import fl.events.ComponentEvent; 
import fl.controls.ComboBox;
import fl.data.DataProvider;
于 2012-10-22T04:36:59.903 回答