7

I want to use the HTML5 FileApi to read a SWF to an OBJECT (or EMBED, if it's better to do?).

My current code crashes on Chrome/Iron (the only stable browser which also supports the xmlhttprequest v2 FormData). I got it to read image data into a on-the-fly created IMG. But the object one crashes the current tab in the browser.

else if (file.type == "application/x-shockwave-flash") {
    var show = document.createElement("object");
    show.type = "application/x-shockwave-flash"
    show.style.width = "100%";
    show.style.height = "100%";
    show.id = "thumb";
    document.getElementById("thumbnails").appendChild(show);

    var reader = new FileReader();
    reader.onload = (function (aImg) { 
        return function (e) { aImg.data = e.target.result; }; 
    })(show);
    reader.readAsDataURL(file);

Do I really read to the object.data part? How is it done right? Anybody know? Or is this incomplete and I have to wait for better implementation?


If you refactor your data structure (assuming id is unique within one dictionary), a comparison could be implemented more efficiently (namely in O(n). Dictionary lookups are O(1). Example:

#!/usr/bin/env python

d1 = {
    1 : {"title" : "title1"},
    2 : {"title" : "title2"},
    3 : {"title" : "title3"},
}

d2 = {
    1 : {"title" : "title1"},
    2 : {"title" : "title3"},
    3 : {"title" : "title4"},
}

for key, value in d1.items():
    if not value == d2[key]:
        print "@", key, "values differ:", d1[key], "vs", d2[key]

# @ 2 values differ: {'title': 'title2'} vs {'title': 'title3'}
# @ 3 values differ: {'title': 'title3'} vs {'title': 'title4'}

Or shorter:

print [ (k, (d1[k], d2[k])) for k in d1 if not d2[k] == d1[k] ]
# [(2, ({'title': 'title2'}, {'title': 'title3'})), \ 
#    (3, ({'title': 'title3'}, {'title': 'title4'}))]
4

1 に答える 1

2

試してみることをお勧めするいくつかのこと(複雑さが増す順序で):

  • base64 でデータをbtoaでエンコードし、 data:URIを使用して設定します。
  • を使用してオブジェクトを作成する代わりに、createElementすべて<object>の属性を HTML 文字列 (上記の base64 アドバイスを含む) としてタグを作成し、それを , で DOM 要素に挿入しますinnerHTML
  • swf コンテンツを POST するリフレクター Web サービスを作成し、URL を提供し、その URL をオブジェクトに渡します。
  • 前と同様に、フルスクリーン IFRAM をターゲットとしてターゲットとして swf コンテンツを POST するリフレクター Web サービスを作成し<object>、サーバーへのポインティング バックを含む HTML ドキュメントをサービスに吐き出させます。

これらのオプションの後者はより集中的であり、サーバーからのラウンドトリップが必要であり、おそらく避けたいと思うでしょう - 考慮したいオプションがいくつかあります.

ActionScript 3 には、Loader同様に役立つ可能性のある があります。URIをサポートしているかどうかはわかりませんが、サポートしている場合data:は、ローカルの swf ファイルの内容を直接実行するブート ローダー SWF を作成できます。

于 2011-07-06T20:40:57.517 に答える