-2

Im trying to insert a music using combo box from the component asset. yesterday works fine, but today suddenly it stopped working and it gave me this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

everytime I clicked on the combo box these error appears, strangely it works fine yesterday. this is the code for the first frame:

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();
     }

and this is the code for the second frame:

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);
    }

the error occurs whenever I clicked on the combo box and when I tried to insert another combo box without putting any data, the same error occurs. hope you guys can help me ASAP cause this is due on friday this week xD

thanks

4

1 に答える 1

0

わかりました、答えが見つかりました。次の 3 行のコードを配置する必要があるようです。

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