[태그:] MP3

  • Sound object can not be reused.

    Sound 객체를 사용할 때 주의해야 할 점은, 재활용이 안된다는 것입니다. 즉, 일회용이라는 것이죠.

    예를 들어 아래 코드와 같이, Sound객체를 생성하여 노래를 로드한 뒤, 나중에 다른 노래를 다시 로드하려고 하면 다음과 같은 에러가 납니다.

    Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful

    var ur:URLRequest = new URLRequest();
    var sound:Sound = new Sound();
    var channel:SoundChannel;
    
    // Loads a song.
    ur.url = "some_song.mp3";
    sound.load(ur);
    channel = sound.play();
    
    // Loads another song.
    ur.url = "another_song.mp3";
    sound.load(ur);
    channel = sound.play();

    그러므로 MP3 파일을 로드할 때마다 Sound 객체를 생성해 주어야 합니다.

    // Loads another song.
    ur.url = "another_song.mp3";
    sound = new Sound();
    sound.load(ur);
    channel = sound.play();