gpt4 book ai didi

flash - 编译到Flash 8时如何让Haxe播放声音文件?

转载 作者:行者123 更新时间:2023-12-02 23:00:45 24 4
gpt4 key购买 nike

我难以让Haxe在Flash 8中播放音频文件。

在我的hx文件的顶部,我有:

import flash.MovieClip;
import flash.Sound;

在类本身中,我预加载了很多图像文件以及音频文件的名称。

这个想法是做一个带有音频内容的幻灯片放映。基本上,显示第一张幻灯片并播放与其关联的音频。

然后,音频播放完毕后,移至下一张幻灯片和下一个音频文件。我的幻灯片可以淡入淡出,但是当我尝试添加声音时,扬声器没有任何声音。

以下代码是我正在执行的操作-与audios [0]关联的声音文件永远不会开始播放,而我对原因感到困惑。
class Whatever {
static var master : MovieClip;
static var slides : Array<MovieClip>;
static var audios : Array<String>;
static var sound : Sound;

function new () {}

static function main () {
master = flash.Lib.current;
slides = new Array<MovieClip> ();
sound = new Sound (null);

var app : Whatever = new Whatever ();
var num : String;
var j : Int;
var clip : MovieClip;

// There are 12 pictures in this test, image[001-012].jpg.
// Each has an associated audioNNN.mp3 file.

for (j in 1...13) {
// Right-justify, zero fill.

num = "" + j;
if (j < 10) num = "0" + num;
if (j < 100) num = "0" + num;

// Load each image, hiding all but the first.

clip = master.createEmptyMovieClip ("clip_" + num, master.getNextHighestDepth());
clip.loadMovie ("image" + num + ".jpg");
if (j > 1) clip._alpha = 0;
slides.push (clip);

// Make another list of the audio files.

audios.push ("audio" + num + ".mp3");
}

// Start the first audio file.

sound.loadSound (audios[0], true);
}
}

最佳答案

傻我!

事实证明,我只是在将值压入数组之前忘记分配数组。为什么运行时允许您做到这一点而没有错误是一个单独的问题。

我要做的就是将代码从以下位置更改:

slides = new Array<MovieClip> ();

至:
slides = new Array<MovieClip> ();
audios = new Array<String> ();

以便正确创建音频阵列。

关于为什么运行时未捕获到不存在的数组的原因, Professional haXe and Neko书中有一个有趣的摘录(仅在今天发布,看起来它很快就会收回我的投资,这就是为什么我不这样做)介意给它一个无耻的插件)来解释它,几乎完全符合我遇到的情况:

So, now that you can see what you're up against, take a look at both Neko and Flash when generating an exception:


class UncaughtException {
public static function main() {
var t : Array <String> ;
t.push("me");
}
}

Compile the preceding class for both Neko and Flash, and then run them both. When run, the Flash player should display a blank screen, while the Neko application will generate the following text:

Called from  line 1
Called from UncaughtException.hx line 6
Uncaught exception - Invalid field access : push

This is an uncaught exception, which means it is an exception that you have not caught and dealt with in your code. The problem with the preceding class is that the Array t was not instantiated before the method push was called, so as far as the virtual machine is concerned, there is no method called push available.

Now, the fact of the matter is, the Flash virtual machine would have hit the same wall that the Neko virtual machine encountered, except that the Flash virtual machine chose to ignore the error and continue as normal. Does this mean the exception was even generated? Maybe, but, like most invisible pests, you'll need to catch one to prove it exists.

关于flash - 编译到Flash 8时如何让Haxe播放声音文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2099763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com