サイト内検索

メインメニュー

ログイン
ユーザID または e-mail:

パスワード:

IDとパスワードを記憶

パスワード紛失

オンライン状況
11 人のユーザが現在オンラインです。 (10 人のユーザが ウェブログ を参照しています。)

 登録ユーザ: 0
 ゲスト: 11

もっと...

ウェブログ カレンダー
« « 2010 9月 » »
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 1 2

最新ブログ記事

最近のコメント

最近のトラックバック

|
ウェブログ - ひろゆきの記事
|
 ひろゆきの記事配信

2007/02/26 Mon
 ExternalInterfaceを使ってみる (2)
カテゴリ: flash : actionscript : 
ExternalInterfaceクラスを使ってみるのだ!
JavaScript と連携できるらしい。(swf -> js -> swf)

要 Flash Player 8 以上


_root にムービークリップ(インスタンス名: agentBtn, locationBtn, queryBtn, browserBtn) を配置。
また、テキストフィールド(インスタンス名: display_txt) も配置。

_root 第1フレームに

import flash.external.ExternalInterface;

agentBtn.onRelease = function():Void {
    var agent:String = String(ExternalInterface.call("getAgent"));
    display_txt.text = agent;
};
locationBtn.onRelease = function():Void {
    var baseURL:String = String(ExternalInterface.call("function() { return window.location.href; }"));
    display_txt.text = baseURL;
};
queryBtn.onRelease = function():Void {
    var query:String = String(ExternalInterface.call("function() { return window.location.search; }"));
    display_txt.text = query;
};
browserBtn.onRelease = function():Void {
    var windowSize:Object = ExternalInterface.call("getWindowSize");
    display_txt.text = "[" + windowSize[0] + ", " + windowSize[1] + "]";
};

と記述。

JavaScript (swf を配置した html)

<script type="text/javascript">
    function getAgent() {
        return navigator.userAgent;
    }
    function getWindowSize() {
        if (window.innerWidth && window.innerHeight) {
            return [window.innerWidth, window.innerHeight];
        } else if (document.body) {
            return [document.body.clientWidth, document.body.clientHeight];
        } else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
            return [document.documentElement.clientWidth, document.documentElement.clientHeight];
        }
        return 0;
    }
</script>


MacOSX 10.3.9 + Safari 1.3.2 / Firefox 1.5.0.4 の環境では、
正常に機能しているよ!


上の例では、<object>タグの id は「externalInterface2」としている。

<object>タグの id は「〜external」「external〜」「〜external〜」などにしないと、
Internet Explorer では、戻り値が null で返ってくるらしい。

参考資料「ExternalInterface.call Internet explorerでnullが返ってくる件


そこで、次の例では、同じswfを用いて、<object>タグの id を「iebug」としてみた。
Internet Explorer では、null が返ってくるのか?


[追記] (10/08/25 Wed 11:00)
null が返ってくる原因は、SWFObject1.5 を使用しているからかもしれない。
SWFObject2.2 だと、正常に機能しているような感じ。[テスト]


関連記事: ExternalInterfaceを使ってみる (1)
関連記事: ExternalInterfaceを使ってみる (2)
関連記事: [AS2.0] Browserクラスとな!
関連記事: ExternalInterfaceを使ってみる (3)
関連記事: ExternalInterfaceを使ってみる (4)
関連記事: ExternalInterfaceを使ってみる (5)
関連記事: [AS3.0] LoaderInfoクラスだ!
執筆者: ひろゆき (18:32)
ウェブログ | コメント (6) | トラックバック数 (0) | 閲覧数 (15155)
この記事のトラックバックURL  リンク・引用のないトラックバックは削除することがあります。
http://www.project-nya.jp/modules/weblog/weblog-tb.php/644
投稿された内容の著作権はコメントの投稿者に帰属します。
投稿者 スレッド
ひろゆき
投稿日時: 07/03/09 10:51  更新日時: 07/03/09 10:51
管理人
居住地: 東京密林
投稿数: 1626
 Re: ExternalInterfaceを使ってみる (2)
ありがとうございます。

nullですね。browserは[undefined,undefined]ですが、その他はnullです。

なるほど。
browser は、配列[0], 配列[1] を取っているので、
[undefined, undefined] になるわけですね。
ゲスト
投稿日時: 07/03/09 02:41  更新日時: 07/03/09 10:48
 Re: ExternalInterfaceを使ってみる (2)
(ゲストの c-geru さんからの投稿)

ごめんなさい。ぼけ倒しで・・・

え〜、確認しました。
nullですね。browserは[undefined,undefined]ですが、その他はnullです。
ひろゆき
投稿日時: 07/03/09 00:05  更新日時: 07/03/09 00:05
管理人
居住地: 東京密林
投稿数: 1626
 Re: ExternalInterfaceを使ってみる (2)
いえ、そういうことではなくて。

記事内の「iebug」の例では、null と表示されますか?
ということをお尋ねしたかったのですが。
ゲスト
投稿日時: 07/03/08 23:27  更新日時: 07/03/09 00:03
 Re: ExternalInterfaceを使ってみる (2)
(ゲストの c-geru さんからの投稿)

私はAS辞書の下記のサンプルを使いました。

<form>
<input type="button" onclick="callExternalInterface()" value="Call ExternalInterface" />
</form>
<script>
function callExternalInterface() {
thisMovie("externalInterfaceExample").goHome();
}

function thisMovie(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName]
}
else {
return document[movieName]
}
}
</script>



で、id="top"とかではwindow[movieName]がちゃんと取れてないみたいで(alertで表示すると一応[object]にはなっている)動作せず、id="top_external"とすると動きました。
ひろゆき
投稿日時: 07/03/08 17:52  更新日時: 07/03/08 17:54
管理人
居住地: 東京密林
投稿数: 1626
 Re: ExternalInterfaceを使ってみる (2)
すると「iebug」の例だと、null が返ってきますか?
ゲスト
投稿日時: 07/03/08 17:05  更新日時: 07/03/08 17:49
 Re: ExternalInterfaceを使ってみる (2)
(ゲストの c-geru さんからの投稿)

毎度お世話になります。
<object>タグの id の件、参考になりました。
まさにはまっていたので・・・(^^;。