2009/06/01

mixiアプリでFlash

mixiアプリが開始して久しいですね。
以下は、mixiアプリでFlashを使うための備忘録です。

以下のガジェットをmixiアプリで登録するものとする。

sample.xml

<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="use Social Data">
<Require feature="opensocial-0.8"/>
<Require feature="flash"/>
</ModulePrefs>
<Content type="html">
<![CDATA[

<script type="text/javascript">
var viewer = new Object(); // globalで必要な変数を宣言

function get_viewer_profile() {
var request = opensocial.newDataRequest();
request.add(request.newFetchPersonRequest(
opensocial.IdSpec.PersonId.VIEWER), "viewer_data");
request.send(function (response) {
var item = response.get("viewer_data");
if (item.hadError()) {
// エラー処理。item.getError() で詳細情報を取得
return;
}

// 実行ユーザのプロフィールを参照
var person = item.getData();

viewer.name = person.getField(opensocial.Person.Field.ID); // ID
viewer.name = person.getField(opensocial.Person.Field.NAME); // 名前
viewer.nickname = person.getField(opensocial.Person.Field.NICKNAME); // ニックネーム
viewer.url = person.getField(opensocial.Person.Field.PROFILE_URL); // プロフィールURL
viewer.icon = person.getField(opensocial.Person.Field.THUMBNAIL_URL); // アイコンURL
viewer.address = person.getField(opensocial.Person.Field.ADDRESSES); // 住所
viewer.age = person.getField(opensocial.Person.Field.AGE); // 年齢
viewer.birthday = person.getField(opensocial.Person.Field.DATE_OF_BIRTH); // 誕生日
viewer.bloodtype = person.getField(mixi.PersonField.BLOOD_TYPE); // 血液型
});
}
gadgets.util.registerOnLoadHandler(get_viewer_profile);

function getMixiPerson(){
return viewer; // 必要な変数を返す
}
</script>

<div id="externalContainer"></div>

<script type="text/javascript">
function show_flash() {
gadgets.flash.embedFlash(
"sample.swf", "externalContainer", "9.0.0",
{
width : 400, // 幅
height : 300, // 高さ
quality : 'high',
wmode : 'transparent',
allowScriptAccess : 'always' // swfからのaccessを許可
}
);
}
gadgets.util.registerOnLoadHandler(show_flash);
</script>

]]>
</Content>
</Module>


上記のガジェット中のsample.swfは以下のソースをビルドしたものとする。

sample.fla
import flash.external.ExternalInterface;

var mixiPerson = ExternalInterface.call("getMixiPerson"); // JavaScriptのgetMixiPerson関数を呼び出す


このとき変数mixiPersonにはmixi上でそのアプリを閲覧している人の情報が格納される。
あとはご自由に!

0 コメント: