Archived:WRT WidgetでJavaScriptからFlash Liteに通信する方法
We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.
Article Metadata
Code Example
Article
必要となるもの:
- Adobe Flash LiteとJavaScriptに関する知識
Contents |
Flash Lite
手順:
1) Flashファイルを作成する。
フレーム1 (ActionScriptレイヤー):
ActionScriptウィンドウ中で、以下の変数を定義します。
var total_ram; var free_ram;
フレーム5:
画面上にテキストボックスを保持するため、新たにレイヤーを作成します(オブジェクトレイヤー)。
画面上の各レイヤーにテキストボックスを2つ作成し、各テキストボックス用に以下の変数を'var'で定義し、割り当てます。
Total_ram_txt Free_ram_txt
次に、画面上にメモリレベルを示すムービークリップを作成します。
注意点: シンボルに変換する時には、画像の下部に示されるように登録(Registration)します。
フレーム5 (ActionScriptレイヤー):
//Set the Interval of updating text boxes on the screen.
var intervalId = setInterval( updateScreen, 1000 ); //1 Second
function updateScreen()
{
if(total_ram != undefined && free_ram != undefined )
{
total_ram_txt = total_ram + " M"; //set Total ram in textfield
free_ram_txt = free_ram + " M"; //set Free ram in textfield
_root.mem_lvl_mc._height = (free_ram*50/total_ram); //Update Level on the screen
}
}
setInterval()関数は組み込みのActionScript関数で、時間間隔(interval)を設定した後、周期的にコードや関数を呼び出します。
ここで、Flashの部分は準備ができました。.swfファイルをパブリッシュし、名前をmemInfo.swfとします。
メインHTML
ここで、以下の内容の.htmlファイルを作成します。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml/"> <head> <title>Memory Info</title> <script language="javascript">AC_FL_RunContent = 0;</script> <script src="AC_RunActiveContent.js" language="javascript"></script> </head> <BODY BGCOLOR="#FFFFFF" onload = "load();"> <embed id="systeminfo" type="application/x-systeminfo-widget" hidden="yes"></embed> <script language="javascript"> if (AC_FL_RunContent == 0) { alert("This page requires AC_RunActiveContent.js."); } else { AC_FL_RunContent( 'codebase', '[http]://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0', 'width', '240', 'height', '320', 'src', 'network_signal240x320', 'quality', 'high', 'pluginspage', 'http://www.macromedia.com/go/getflashplayer', 'align', 'middle', 'play', 'true', 'loop', 'true', 'scale', 'showall', 'wmode', 'window', 'devicefont', 'false', 'id', 'memInfo', 'bgcolor', '#ffffff', 'name', 'memInfo', 'menu', 'true', 'allowFullScreen', 'false', 'allowScriptAccess','sameDomain', 'movie', 'memInfo', 'salign', '' ); //end AC code } </script> <noscript> <OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0', ID=memInfo align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="allowFullScreen" value="false" /> <param name="movie" value="memInfo.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed src="memInfo.swf" quality="high" bgcolor="#ffffff" width="240" height="320" name="memInfo" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </OBJECT> </noscript> </div> </BODY> </HTML>
注意点: {{{1}}} は、バッテリーレベル、ネットワークレベル、使用可能なメモリ量などといった、システム情報へアクセスできるようにするために使われるものです。このタグは、<body>タグの下に定義する必要があります。
Flash埋め込みオブジェクト中にある 'name' 属性中の値(例: "memInfo")は、JavaScriptがFlashと通信するために使うものです。
JavaScript
JavaScriptファイルのコード:
//USER DEFINED VARIABLES
var sysinfo = null;
var drives = 0;
var totalRamSize;
var freeRamSize;
var space;
var loop = 0;
//---USER FUNCTIONS
function load()
{
sysinfo = document.embeds[0]; //Must for accessing system attributes
Runtimer();
}
function Runtimer()
{
//Calls itself every 2 second and calls AC_communicateWithFlash() function
t=setTimeout("Runtimer()",2000); //2 Second
if(loop != 0)
{ AC_communicateWithFlash();}
loop = 1;
}
function checkRamSpace()
{
// get total RAM size in bytes
totalRamSize = sysinfo.totalram;
space = Number(Number(totalRamSize) / Number(1048576)); //MB
totalRamSize = space.toFixed(2);
// get free RAM size in bytes
freeRamSize = sysinfo.freeram;
space = Number(Number(freeRamSize) / Number(1048576)); //MB
freeRamSize = space.toFixed(2); //Display 2 Decimal Place
}
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}
function AC_communicateWithFlash()
{
//this function checks for Current Ram Space and Drives Space
//and sets the values inside flash.
checkRamSpace();
//memInfo defined in HTML file used for referencing flash Object
var flashMovie=getFlashMovieObject("memInfo");
//following steps assigns the JAVASCRIPT variables values to flash variables placed on
the root timeline.
flashMovie.SetVariable("/:total_ram",totalRamSize);
flashMovie.SetVariable("/:free_ram",freeRamSize );
}
ダウンロード
ソースコードのダウンロード: Media:MemInfo.zip.
本パッケージは、Flashソースファイル、JavaScriptファイル、その他の関連ファイルを含んでいます。


(no comments yet)