U10はFlash Lite 1.1をサポートしていますが、現在のところ、U10には開発用のエミュレータがありません。 そこで、実際のパフォーマンスをテストするには、完成したコンテンツをU10に移す必要があります。 Flash Lite 1.1でのパブリッシングの代わりに、Flash 4にパブリッシュし、それからSWFファイルをU10に移してパフォーマンスをチェックするという方法をお勧めします。
Flash 4にコンテンツをパブリッシュする際には、以下のことに留意してください。
_root の下の該当するインスタンス(ムービークリップ)をスラッシュによって次のように特定します。 /instanceName/instanceName.../ および ./ を使って、 this や _parentなどの関連パスを指定できます。| Flash 8 | Flash 4 |
|---|---|
_root.instance._visible=false; |
/instance:_visible = false; |
_parent.myName="MiniGate"; |
../:myName = "MiniGate"; |
this.instance.dx = 3; |
instance:dx = 3; |
たくさんのキーを持つデスクトップコンピュータや電話とは異なり、iRiver U10では、上下左右の4つのナビゲーションボタンと、+と-の2つの音量ボタンしか使えません。 ナビゲーションボタンは、上下左右4方向のカーソルキーに対応し、音量ボタンはPageUpとPageDownに対応します。
下の例に示されるように、これを一般的なボタンクリップのように使うことができます。
// U10 Up button event
on (keyPress "<Up>") {
// Handle Up button event
}
// U10 volume + button event
on(keyPress "<PageUp>") {
// Handle Volume Up button event
}
この記事の冒頭にリンクを設定しているサンプルファイルをダウロードすれば、この例(図1参照)のソースファイルをご覧いただけます。
図1. キーマッピングのサンプル(sample1.swf)
Flash Lite 1.1では onClipEventを使いません。 したがって、図1と同じ状態を作り出すには、フレームを動かす必要があります。
作成されたムービークリップのフレーム1に、 onLoadに移動するコンテンツを入力します。 また、フレーム2に、 onEnterFrameに移動するコンテンツを入力します。 そして最後にフレーム3(図2参照)に、 gotoAndPlay(2);と入力します。 ムービークリップが表示されると、まずフレーム1(onLoad)を実行し、続いてフレーム2(onEnterFrame)のアクションを繰り返し再生します。
図2. フレーム1、2、および3のActionScript
Flash Lite 1.1はアレイをサポートしていないため、変数を1つずつ挙げていかなければなりません。 ただし eval() をアレイのように使うことはでき、次の例のように、パラメータとして入力したストリングによって表されるオブジェクトまたは変数の値が戻ります。
eval("a") = 3; //Save 3 in the variable of a.
eval("a" add 3) = 12; // Save 12 in the variable of a3.
eval("/instance:myName") = "MiniGate"; //In the myName variable in the instance movie clip,
save "MiniGate".
アレイを模した使い方の例を示します。
//The values from 0 to 9 is saved in the variables from a0 to a9.
for(i=0; i<10; i++){
eval("a" add i) = i;
}
Flash Lite 1.1は関数をサポートしていません。 ただし、関数の代わりに call() を使用できます。 次の例は、Flash 8の関数と call()を使用してFlash 4でそれを模す方法を示しています。
Flash 8:
function name () {};
// execute the name function.
name();
Flash 4:
Insert a script in the frame labeled name
// Use call() to run a script in a corresponding frame.
call("name");
Flash Lite 1.1はムービークリップの直接制御をサポートしていません。 ムービークリップの制御には、 tellTarget()を使用します。 次の例は、Flash 8でのムービークリップの直接制御方法と、 tellTarget() を使用してFlash 4でそれを模す方法を示しています。
Flash 8:
chicken.wing.gotoAndPlay(1)
Flash 4:
tellTarget("chicken/wing") {
gotoAndPlay(1)
}
Flash 4では、ストリング演算と数値とを区別しなければなりません。 add 演算子を使用してストリングを結合し、 eq および ne 演算子を使用してストリングを別のストリングと比較します。 ストリング演算の = または + 演算子と混同しないよう気をつけてください。
次の例は、Flash 8の演算子と、それに対応するFlash 4のストリングを示しています。
"Mini" + "Gate" -> "Mini" add "Gate" _parent.yourName == "MiniGate" -> ../:yourName eq "MiniGate" yourName != "BigGate" -> yourName ne "BigGate"
Flash 4では、ブール値は0や1のような数値に変換されます。実際にコードを記述する際には、 true または falseを使用できます。 ただし、ブール値は1または0として認識されることを覚えておいてください。
firstData = true; secondData = false; result = firstData add " : " add secondData; trace(result); //trace is "1 : 0"
Flash 4にはインスタンスの参照がありません。 内蔵の機能を使用するためのパラメータにインスタンス名を付ける場合は、「ストリング」形式で入力しなければなりません。 例えば tellTarget()の場合なら、ターゲットインスタンス名は、 /instance/subを挿入すると特定できます。 /instance/subではありません。
このことはFlash 4で作業をする際に混乱を招くことがあります。ですが、インスタンスの参照がないということに留意すれば、問題にはなりません。
誤った例:
tellTarget(myInstance) {}
正しい例:
tellTarget("myInstance") {}
誤った例では、 myInstance がムービークリップではなく変数として識別され、 tellTarget("") {}と同じように捉えられてしまいます。
Flash Liteは FSCommand2() を使用してiRiver U10のデバイス情報を取得します。 FSCommand2()には数種類のコマンドがあります。 デフォルトでは、U10用の最も一般的なコマンドは以下に示すとおりです(図3も参照)。
Date(Year, Month, Day)
fscommand2 ("GetDateYear");
fscommand2 ("GetDateMonth");
fscommand2 ("GetDateDay");
Time(Hour, Minute, Second)
fscommand2 ("GetTimeHours");
fscommand2 ("GetTimeMinutes");
fscommand2("GetTimesec");
fscommand2 ("GetDevice", "devicename");
// Retrieve the name of device.
fscommand2 ("GetDevice", "devicename");
trace(devicename); // Trace is "iriver U10"ta
fscommand2 ("GetMaxBatteryLevel");fscommand2 ("GetBatteryLevel");
// Retrieve total battery level.
maxBatt = fscommand2 ("GetMaxBatteryLevel");
// Retrieve current battery level.
battLevel = fscommand2 ("GetBatteryLevel");
tellTarget ("battery") {
// Move the battery movie clip by the extent that the current battery level indicates.
gotoAndStop (../:battLevel + 1);
}
fscommand2 ("GetTotalPlayerMemory");fscommand2 ("GetFreePlayerMemory");fscommand2("Get", "Picture", "Total", "totalpic")fscommand2("Get", "Picture", "Path", pic_num, "url")
totalpic = 0 // the number of images
pic_num = 1 // Image index number
// Retrieve the number of images that U10 contains.
status = fscommand2("Get", "Picture", "Total", "totalpic")
if (totalpic > 0) {
// Retrieve the image path that corresponds to the image index number.
status = fscommand2("Get", "Picture", "Path", pic_num, "url")
// Retrieve an image to the back movie clip.
loadMovie(url, "back");
}
fscommand2 ("Quit");
図3. U10用の一般的なコマンドの例(sample3.swf)