我正在尝试使用 Adobe Animate CC 中的 ActionScript 3.0 运行代码来显示 30 个不同的图像,每个图像都有自己的 30 秒音乐剪辑。我在尝试循环播放该集合时遇到问题(在播放显示图像的歌曲后加载下一个图像)。我可以加载第一个图像和 30 秒的歌曲,但它不会继续循环到集合。我有一个数字变量,用来指向系统上的艺术文件和歌曲。在尝试移动到下一个图像和声音文件之前,我已成功检查以确保声音文件已播放完毕,但是当我尝试将代码包含在循环中时,它会出现错误:
函数调用顺序不正确,或者之前的调用不成功。在 flash.media::Sound/_load() 在 flash.media::Sound/load()
任何帮助表示赞赏。谢谢。
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?
}
}