声音类型未找到错误

发布于 2024-09-09 22:42:47 字数 529 浏览 4 评论 0原文

我是 ActionScript 的新手。我想将声音动态添加到我的 flv 中。我有这个代码。我很确定它有效,因为我在教科书中找到了它。 :(。

package{
 import flash.display.Sprite;
 import flash.media.Sound;
 import flash.net.URLRequest;
 
 public class soundLoader extends Sprite{
  private var sound:Sound;
  
  public function soundLoader(){
   sound = new Sound(new URLRequest("sound.mp3"));
   addChild(sound);
  }

 }
 
}

当我尝试运行代码时,我收到了这些错误消息。

1046:未找到类型或不是编译时常量:声音。

1180:调用可能未定义的 Sound 方法。

我哪里做错了?拜托,请帮助我。

I am a newbie for ActionScript. I would like to add Sound dynamically to my flv. I have this code. I am pretty sure it is working because I found it in Textbook. :(.

package{
 import flash.display.Sprite;
 import flash.media.Sound;
 import flash.net.URLRequest;
 
 public class soundLoader extends Sprite{
  private var sound:Sound;
  
  public function soundLoader(){
   sound = new Sound(new URLRequest("sound.mp3"));
   addChild(sound);
  }

 }
 
}

When I try to run the code I got these error messages.

1046: Type was not found or was not a compile-time constant: Sound.

1180: Call to a possibly undefined method Sound.

Where did I do wrong? Please,please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄居人 2024-09-16 22:42:47

这段代码有一些问题。
首先,按照惯例,AS3 中的类名以大写字母开头,因此您应该将类​​重命名为 SoundLoader 而不是 soundLoader。
其次,AS3 中的 Sound 对象不是显示对象,因此您无法将其添加到 sprite 的显示列表中。因此对 addChild( sound ) 的调用是错误的,并且会导致编译错误。

但这并不能解决你的问题。您使用 Flash 还是 Flex 来编写此代码?

There are a few things that are wrong with this code.
First of all, by convention class names in AS3 start with an upper case letter, so you should rename your class SoundLoader and not soundLoader.
Second, the Sound object in AS3 is not a display object so you can't add it to a sprite's display list. Therefor the call to addChild( sound ) is wrong, and will cause compile errors.

That doesnt solve your probleme however. Are you using Flash or Flex to write this code ?

缺⑴份安定 2024-09-16 22:42:47

这是我的 Flash 文件: http://www.signalsondisplay.com/sotest.rar
我是用Flash CS4写的,不知道用CS3能不能打开。希望它有帮助,因为我不知道你为什么会收到这个错误。尝试检查您的类路径以及 swf 设置中的此类内容。

here is my flash file: http://www.signalsondisplay.com/sotest.rar
I wrote it in Flash CS4 so I don't know if you can open it with CS3. Hope it helps, because I have no idea why you get that error. Try checking your classpath and that sort of stuff in the swf settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文