I'm trying to run code to show 30 different images each that have their own 30- second music clip using ActionScript 3.0 in Adobe Animate CC. I'm having a problem trying to loop through the set (load the next image after the song for the image shown plays). I can get the first image and 30-second song to load, but it won't continue looping through to the set. I have a numeric var I'm using to point to the art file and song on my system. I'm successfully checking to ensure the sound file is done playing before trying to move to the next image and sound file, but when I attempt to enclose the code in a loop, it coughs up the error:
Functions called in incorrect sequence, or earlier call was unsuccessful. at flash.media::Sound/_load() at flash.media::Sound/load()
Any help is appreciated. Thanks.
import flash.display.MovieClip;
import flash.display.Loader;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.events.Event;
var songart:Number = 1;
// Create directory variables
var imgs:String = "F:/Synthsation/Web and Flash Design/Adobe Animate/Duke_Nukem_TLB_Album_Art/Album_Art/";
var music:String = "F:/Synthsation/Web and Flash Design/Adobe Animate/Duke_Nukem_TLB_Album_Art/Song_Tracks/";
// Create Loader and movie clip variables
var imageLoader:Loader = new Loader();
var songclip:Sound = new Sound();
// Begin processing
// Loop through the album art and load the appropriate music clip
// set songart to begin at 1 and loop until completed
// for (songart = 1; songart < 31; songart++) {
while (songart < 31) {
// Convert the song number into a string
var songString:String = String(songart);
// ------ QUEUE UP THE MUSIC ----------
var mp3request:URLRequest = new URLRequest(music + songString + ".mp3");
songclip.load(mp3request);
// Create sound channel variable and tie it to sound object
var channel:SoundChannel = songclip.play();
songclip.play();
// ------ LOAD THE PICTURE -----
var picrequest:URLRequest = new URLRequest(imgs + songString + ".jpg");
imageLoader.load(picrequest);
// Add picture and position at top left of stage
addChild (imageLoader);
imageLoader.x = 0;
imageLoader.y = 0;
channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
// Determine if the song has finished playing. If so loop to next iteration
function onPlaybackComplete(event:Event): void
{
// trace("DONE PLAYING!");
trace(songart);
//removeChild (imageLoader); < --- necessary for next image?
}
}