0
我可以從外部庫加載圖形但沒有問題,但由於某些原因,所有音頻都不會加載/玩。flash as3試圖從外部swf播放音頻並獲取消息「調用可能未定義的方法」
這裏的loader類我使用...
package
{
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.Font;
public class LoadLibrary extends MovieClip
{
private var gear:MovieClip = new mcGear();
private var txtLoading:BlankClip;
private var _gameLib:String = "";
private var _Impact:Font = new Impact();
public function LoadLibrary(gameLibrary:String)
{
_gameLib = gameLibrary;
addChild(gear);
gear.x = 512;
gear.y = 384;
gear.alpha = .2;
gear.scaleX = .33;
gear.scaleY = .33;
txtLoading = new BlankClip(_Impact, "LOADING...", -400, -60, 800, 120, 26, "center", 5);
addChild(txtLoading);
txtLoading.x = 512;
txtLoading.y = 525;
txtLoading.alpha = .2;
var request:URLRequest = new URLRequest(_gameLib);
LoadVars.LIBLOADER.contentLoaderInfo.addEventListener(Event.COMPLETE, gameLibraryLoaded);
LoadVars.LIBLOADER.load(request);
}
private function gameLibraryLoaded(e:Event):void
{
removeChild(gear);
removeChild(txtLoading);
LoadVars.LIBLOADER.contentLoaderInfo.removeEventListener(Event.COMPLETE, gameLibraryLoaded);
var loaderInfo:LoaderInfo = LoaderInfo(e.currentTarget);
LoadVars.APPDOMAIN = loaderInfo.applicationDomain;
dispatchEvent(new GameEvents(GameEvents.LIBRARY_LOADED));
}
}
}
,並在我的主類的功能...
private function loadLib():void
{
_loadGraphics = new LoadLibrary("Elemental_Library.swf");
addChild(_loadGraphics);
_loadGraphics.addEventListener(GameEvents.LIBRARY_LOADED, test);
}
private function test(e:GameEvents):void
{
trace("LOADED");
var music:Sound = new GameMusic();
music.play();
}
一切工作正常,直到我嘗試music.play和我得到「1180:調用一個可能未定義的方法GameMusic。」我嘗試了其他幾個音頻剪輯,並收到相同的消息。我試着創建一個新庫,並導入一個音頻文件,同樣的消息。我驗證了我正在使用正確的鏈接名稱,瘋狂的部分是所有的影片剪輯都從同一個庫中加載得很好。
你有聲音在External_Library.fla爲ActionScript導出? – ezekielDFM
哪一行出錯? – csomakk
哇,我明白了。總ID10T錯誤。 我忘了告訴它從外部swf加載音樂。更改測試... \t私有功能測試(E:GameEvents):無效 \t { \t \t跟蹤( 「裝」); \t \t \t \t var musicClass:Class = Class(LoadVars.APPDOMAIN.getDefinition(「GameMusic」)); \t \t var music:Sound = Sound(new musicClass()); \t \t music.play(); \t \t \t \t} 我知道這是愚蠢的:P –