私が作成した一連のAir Desktopゲームがあります。作業を合理化するために、私は別のプロジェクトにログインシステムを作成し、それをswfファイル "dashboard.swf"として保存しました。ゲームを開くと、dashboard.swfが読み込まれ、ログイン画面が表示されます。ログイン機能に加えて、dashboard.swfはゲームの共通設定のような他のものを扱います。AS3 Air Desktop - ApplicationStorageDirectory内のSWFからのカスタムイベントの送信
私はダッシュボードを変更するたびに各ゲームを再コンパイルしたくありませんでした。だから、私はそれをサーバーからダウンロードしました。私はもともとApplicationDirectoryにdashboard.swfをダウンロード、保存、ロードしていて、Mac上で正常に動作していました。 Window 10でテストしていくつかの調査をしたところ、OSX以外のマシンのApplicationDirectoryは読み取り専用であることがわかりました。
したがって、ダッシュボードの場所をApplicationStorageDirectoryに変更しました。私はswfファイルのロードがうまく、私のMac上でそれを実行しますが、派遣ます最初のカスタムイベントをスローし、エラー時:
TypeError: Error #1034: Type Coercion failed: cannot convert com.thisapp.event::[email protected] to com.thisapp.event.CustomEvent
両方CustomEvent.asファイルは同一です。 dashboard.swfがMacのApplicationDirectoryに保存され、そこからロードされるときにはうまくいきます。 ApplicationStorageDirectoryに移動すると、このエラーが発生します。だから私は実際のカスタムディスパッチャの問題ではないことを知っています。バブルは真実で、Cancellableではそうです。
このような状況で型強制が失敗する原因は何ですか?
var dashboardURL:String = File.applicationStorageDirectory.url +"dashboard.swf";
var myContext:LoaderContext = new LoaderContext();
myContext.applicationDomain = ApplicationDomain.currentDomain;
var urlReq:URLRequest = new URLRequest(dashboardURL);
var ldr:Loader = new Loader();
ldr.load(urlReq, myContext);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loadit);
function loadit(e:Event){
dashboard = e.target.content as MovieClip;
addChild(dashboard);
dashboard.addEventListener(CustomEvent.GOT_RESULT, runLogin);
}
ANSWER を参照してください:デスクトップアプリケーションのための私のメインクラスでは
dispatchEvent(new CustomEvent(CustomEvent.GOT_RESULT, null,true,true));
:私のdashboard.swfから
public class CustomEvent extends Event {
public static const GOT_RESULT: String = "gotResult";
public var result: Object;
public function CustomEvent(type: String, result: Object = null, bubbles: Boolean = false, cancelable: Boolean = false) {
// constructor code
super(type, bubbles, cancelable);
this.result = result;
}
public override function clone(): Event {
return new CustomEvent(type, result, bubbles, cancelable);
}
}
:
は、ここに私のカスタムディスパッチャです@ BadFeelingAboutこれはアンデへの答えです1034エラーが発生している理由を確認してください。ここで私はそれを固定方法は次のとおりです。
ファースト - (私はGreenSockのLoaderMaxを使用しています)、サーバーからSWFをダウンロードします。
private function dowloadDashboard(){
var url:String = "https://path/to/your/swf/on/the/server.swf";
var queue:LoaderMax = new LoaderMax({name:"mainQueue",onComplete:completeHandler});
//Note: the format is set to "binary"
queue.append(new DataLoader(url, {name:"mySwf",format:"binary", estimatedBytes:3000}));
queue.load();
function completeHandler(event:LoaderEvent):void {
//Note: "mySwf" is the name I gave to the DataLoader above.
var b:ByteArray = LoaderMax.getContent("mySwf");
//loadDashboard() is the next function and I'm passing the ByteArray to it.
loadDashboard(b);
}
}
次 - のByteArrayを使用して、適切なコンテキストにswfファイルをロードします。
private function loadDashboard(b:ByteArray) {
var myContext:LoaderContext = new LoaderContext();
myContext.allowLoadBytesCodeExecution = true;
myContext.allowCodeImport = true;
myContext.applicationDomain = ApplicationDomain.currentDomain;
var ldr:Loader = new Loader();
ldr.loadBytes(b,myContext);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,loadDone);
}
最終 - ステージにあなたのswfファイルを追加します。
function loadit(e:Event){
dashboard = e.target.content as MovieClip;
addChild(dashboard);
}
私はそれが誰かを助け願っています!私の状況では、サーバー上に存在するswfファイルをダウンロードして読み込んでいるDesktop Airアプリケーションがあります。
についてもっと読むロードされたSWFの
CustomEvent
でホスト
CustomEvent
を上書きする必要がありますか?ほとんどの場合、ルートパスが異なるため、セキュリティサンドボックスは異なりますが、実際には同じではありませんが、2つのクラッシュするクラスがあります。 – BadFeelingAboutThis@BadFeelingAbout - そうです。 dashboard.swfがApplicationDirectoryからロードされたときに正常に動作します。この問題が発生したApplicationStorageDirectoryからロードされたときです。したがって、実際のコードが動作します。それはファイルの場所と関係があり、私はなぜそれを理解することはできません。 – Tony
最後の例のように、ローダーコンテキストを 'currentDomain'に設定してみてください:http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7de0.html – BadFeelingAboutThis