Google Swiffyを試してみました。【4.FlashVars的データ渡し】

Google Swiffyを試す。第4回です。

今回はFlashVars的データ渡しのお話です。

外部から値を渡す方法はFAQに以下のような記述があります。

How can I support the clickTAG parameter?

Flash ads commonly use the clickTAG parameter to enable click tracking. You can pass this parameter to your Swiffy file by inserting the following code snippet in the Swiffy output, just before the call to stage.start():

stage.setFlashVars(“clickTAG=http://www.google.com”);

というわけで、stage.setFlashVarsで渡せるので試してみます。

今回のソース

FLASH
[SWF]https://www.1ft-seabass.jp/memo/archives/google_swiffy_004/google_swiffy_004.swf,200,200[/SWF]

.fla(CS4作成)データダウンロード:google_swiffy_004.zip

いまundefinedなのはFlashVarsを渡していないためです。
テキストフィールドが3つ並んでおり以下のコードで値 fv が外部から渡される値をsplitで分解し割り振ります。
splitが使えるかも試してます。

// 値 fv が外部から渡される値。
// fv ="1,2,3";

// splitで分解し各テキストに割り振る。
var fvarr = fv.split(",");

tf1 = fvarr[0];
tf2 = fvarr[1];
tf3 = fvarr[2];

fv=テキスト1,テキスト2,テキスト3をFlashVarsで渡すと以下のようになります。

[SWF]https://www.1ft-seabass.jp/memo/archives/google_swiffy_004/google_swiffy_004.swf,200,200,fv=テキスト1,テキスト2,テキスト3[/SWF]

それでは変換してみます

まず、変換されたものは以下の通りです。まだ値が渡されていないので真っ黒です。
値がない際の挙動はFlashと同様、undefinedになりませんね。

別ページで開く

ソースはデータ部分は割愛しますが、以下のようになります。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Swiffy output</title>
<script src="http://www.gstatic.com/swiffy/v3/runtime.js"></script>
<script>
swiffyobject = **データ部分は割愛します**
</script>
</head>
<body style="overflow:hidden;margin:0;">

<script>var stage = new swiffy.Stage(document.body, swiffyobject);</script>
<script>stage.start();</script>

</body>
</html>

stage.setFlashVars で値を渡してみる

では早速以下のようにHTMLに書き加えてstage.setFlashVars で値を渡してみます。

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Swiffy output</title>
<script src="http://www.gstatic.com/swiffy/v3/runtime.js"></script>
<script>
swiffyobject = **データ部分は割愛します**
</script>
</head>
<body style="overflow:hidden;margin:0;">

<script>var stage = new swiffy.Stage(document.body, swiffyobject);</script>
<script>stage.setFlashVars("fv=テキスト1,テキスト2,テキスト3");</script>
<script>stage.start();</script>

</body>
</html>

さて、どうなるでしょう?

別ページで開く

うまく行きました!

加えて、splitも「テキスト1」という日本語の値もうまくいっています。素晴らしい。

おわりに

FlashVars的なことができると、例えば、外部からデータが送ることが出来るのでバナーで動的に飛び先を変えたりするようなコンテンツが可能ですし、GoogleSwiffyでは、まだデータをロードするようなことはできないのでサーバーサイドで取得した情報を事前に埋め込んで渡すことで代用も出来ます。

それでは、ピンと来ましたらサンプルで実際に試していただければと思います。