私はSpriteを拡張するBuildingSpriteを持っています。私は主なアプリケーションに外部swfライブラリを読み込もうとします。外部swfを読み込んでカスタムクラスに割り当てます
私はこのコードを持っており、それが正常に動作します:
private function loadBuilding():void{
// this context is necessary to find the shared assets
var context:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
// load in the asset swf
var loader:Loader = new Loader();
var req:URLRequest = new URLRequest("assets/Tree.swf");
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onAssetsLoaded);
loader.load(req, context);
}
private function onAssetsLoaded(_event:Event):void{
// get a reference to the loaded library
var loader:Loader = LoaderInfo(_event.target).loader;
var library:* = loader.content;
var assetClass:Class = loader.contentLoaderInfo.applicationDomain.getDefinition("Tree") as Class;
// create an instance of the shared asset
var mySprite:Sprite = new assetClass();
.....
}
私は新しいクラス作成 - BuildingSpriteスプライトを拡張します。
package
{
import flash.display.Sprite;
public class BuildingSprite extends Sprite
{
public function BuildingSprite()
{
super();
}
}
}
そして、上記onAssetsLoadedからを、私は、コードを変更します。
var mySprite:Sprite = new assetClass();
~
var mySprite:BuildingSprite = new assetClass();
私はデバッグし、このエラーを取得: メインスレッド(:TypeError例外:エラー#1034:型変換に失敗しました:一時停止をすることはできません 変換BuildingSpriteにツリーの@ c8f0301。)私が思う
型キャストエラーがあります。 外部swfライブラリを読み込んでカスタムクラスに割り当てる方法はありますか?ここ