Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 01:42, 5 August 2008.

Web Runtime WidgetのJavaScriptでFlash Liteと通信する方法

From Forum Nokia Wiki


原文(英語): How-to communicate with Flash Lite from Javascript in widget (WRT)

必要事項:

Flash Liteの知識

JavaScriptの知識


Contents

Flash Lite

ステップ:

1) Flashファイルを作成する

フレーム番号1

("actionscript"レイヤ)

アクションスクリプトウィンドウで、下記変数を定義します。

  var total_ram;
  var free_ram;


フレーム番号5

画面上にテキストボックスを持つレイヤを新たに作成します。

("objects"レイヤ)

スクリーン上にテキストボックスを2つ別々のレイヤで作成し、テキストボックス用に'var'で定義した変数を割当てます。

  Total_ram_txt   
  Free_ram_txt

そして、メモリ容量のレベルを示すため、画面上にムービークリップを作成します。

Image:MemInfo.JPG

注意事項: 「シンボルに変換」(Convert to Symbol)において、「基準点」(Registration)を以下に示す画像のように(bottom)します。

Image:MemInfo2.JPG


フレーム番号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()関数は、組込みのアクションスクリプト関数です。時間間隔を設定した後、定期的に部分コードまたは関数を呼出します。

これで、Flash部分の作成は終了です。

SWFファイルをパブリッシュし、その名前をmemInfo.swfとします。



Main 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>


注意事項:

<embed id="systeminfo" type="application/x-systeminfo-widget" hidden="yes"></embed>

上記タグを使用することにより、バッテリーレベル、ネットワーク強度、使用可能なメモリ量といったシステム情報へアクセスすることができます。

またこれは、<body>タグの中で定義する必要があります。

Flash埋め込みオブジェクト(<embed>タグ)中の'name'属性の値は、JavaScriptがFlashファイル(ここでは"memnfo")と通信するために使用します。



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

ファイル中に含まれているもの:

1. Flashソースファイル

2. JavaScriptとその関連ファイル

リンク

Related Discussions
Thread Thread Starter Forum Replies Last Post
WRT with Paypal hp3 WRT Widget Development 3 2008-04-25 15:06
runtime error in s60 sdk, 2nd edition, fp3 cstommijx Mobile Java Tools & SDKs 4 2006-10-27 04:00
problem with N80 abolfoooud Mobile Java General 6 2006-06-16 15:25
DRM - separate delivery, getting 403 Forbidden biskero Digital Rights Management & Content Downloading 6 2006-09-26 12:11
How to Break line at runtime int Text Editor? omerkarim Symbian User Interface 4 2007-11-14 12:19
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX