Flash开发声音问题
FlashDevelop sound problems
我的目标是创建一个 Asteroids 克隆,我有游戏集,可以在 chrism 网络教程上找到。我已经几乎完全设置好游戏,但是,当我添加声音时,程序会报错并出现以下错误。
\src\Main.as(21): col: 3 Error: Access of undefined property soundClip.
\src\Main.as(20): col: 17 Error: Type was not found or was not a compile-time constant: Sound.
代码显示在这里:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
/**
* ...
* @author Chris Moeller
* http://www.chrismweb.com
* Tutorial: Creating an Asteroids Game: Part 4
*/
public class Main extends Sprite
{
[Embed(source = "snd/9mmshot.mp3")]
private const embeddedSound:Class;
var soundClip:Sound = new embeddedSound(); // Bullet
soundClip.play(); // Play the sound
private var game:Game;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
//create the game object passing in the swf width and height
game = new Game(stage.stageWidth, stage.stageHeight);
//add the game bitmap to the screen/ Main.as Sprite to make it visible
addChild(game.bitmap);
//Create the main game loop
addEventListener(Event.ENTER_FRAME, Run);
//add keylisteners
stage.addEventListener(KeyboardEvent.KEY_DOWN, game.KeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, game.KeyUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, game.MouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, game.MouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, game.MoveMouse);
}
private function Run(e:Event):void
{
game.Update();
game.Render();
}
}
}
我已经尝试研究这个问题但没有成功,我什至检查了一些使用该程序添加声音的教程。
我什至降低了网上找到的音质
但运气不好,我不知道发生了什么。请帮忙!!
任何帮助将不胜感激!
我使用在线音频转换器来转换音频。
为了避免您的第一个错误 (Error: Type was not found or was not a compile-time constant: Sound.
),您必须将 Sound
class 导入到您的 class 中:
// ...
import flash.media.Sound;
对于第二个错误,你应该知道你不能在函数外使用你的soundClip
对象,那部分只是声明(和初始化)你的对象,所以你可以这样做,例如:
private function shotFunction(): void
{
soundClip.play();
}
希望能帮到你。
我的目标是创建一个 Asteroids 克隆,我有游戏集,可以在 chrism 网络教程上找到。我已经几乎完全设置好游戏,但是,当我添加声音时,程序会报错并出现以下错误。
\src\Main.as(21): col: 3 Error: Access of undefined property soundClip.
\src\Main.as(20): col: 17 Error: Type was not found or was not a compile-time constant: Sound.
代码显示在这里:
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
/**
* ...
* @author Chris Moeller
* http://www.chrismweb.com
* Tutorial: Creating an Asteroids Game: Part 4
*/
public class Main extends Sprite
{
[Embed(source = "snd/9mmshot.mp3")]
private const embeddedSound:Class;
var soundClip:Sound = new embeddedSound(); // Bullet
soundClip.play(); // Play the sound
private var game:Game;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
//create the game object passing in the swf width and height
game = new Game(stage.stageWidth, stage.stageHeight);
//add the game bitmap to the screen/ Main.as Sprite to make it visible
addChild(game.bitmap);
//Create the main game loop
addEventListener(Event.ENTER_FRAME, Run);
//add keylisteners
stage.addEventListener(KeyboardEvent.KEY_DOWN, game.KeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, game.KeyUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN, game.MouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, game.MouseUp);
stage.addEventListener(MouseEvent.MOUSE_MOVE, game.MoveMouse);
}
private function Run(e:Event):void
{
game.Update();
game.Render();
}
}
}
我已经尝试研究这个问题但没有成功,我什至检查了一些使用该程序添加声音的教程。
我什至降低了网上找到的音质
但运气不好,我不知道发生了什么。请帮忙!! 任何帮助将不胜感激! 我使用在线音频转换器来转换音频。
为了避免您的第一个错误 (Error: Type was not found or was not a compile-time constant: Sound.
),您必须将 Sound
class 导入到您的 class 中:
// ...
import flash.media.Sound;
对于第二个错误,你应该知道你不能在函数外使用你的soundClip
对象,那部分只是声明(和初始化)你的对象,所以你可以这样做,例如:
private function shotFunction(): void
{
soundClip.play();
}
希望能帮到你。