【发布时间】:2015-12-08 02:34:01
【问题描述】:
我的目标是创建一个 Asteroids 克隆,我有游戏集,如 chrism 网络教程中所示。我几乎完成了游戏设置,但是,当我添加声音时,程序抱怨以下错误。
\src\Main.as(21): col: 3 Error: Access of undefined property soundClip.
\src\Main.as(20): col: 17 错误:找不到类型或不是编译时常量:声音。
代码如下:
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();
}
}
}
我已经尝试研究这个问题,但没有运气,我什至检查了一些使用该程序添加声音的教程。
我什至降低了网上找到的音质
但这里没有运气,我不知道发生了什么。请帮忙!! 任何帮助将不胜感激! 我使用在线音频转换器来转换音频。
【问题讨论】:
标签: actionscript-3 flash flashdevelop