
 |
|

|
◆4. 共有オブジェクトの定義
「監視カメラで動きを感知したら、監視モニタに警告音を出す」というデータを、リモート共有オブジェクトを使って定義します。
14: function initSO()
{
15: so = SharedObject.getRemote("Alert",
nc.uri);
16: so.onSync = function() {
17: isSound = so.data.sound;
18: startSound();
19: };
20: so.connect(nc);
21: } |
(14〜15)getRemoteメソッドを実行して、リモート共有オブジェクトを生成します。「Alert」という名前で共有し、NetConnectionオブジェクトのURIは、「nc.uri」と記述します
(監視カメラと記述を合わせます) 。
(16)FCSに接続しているすべてのユーザでデータを共有するために「onSync」を呼び出して、function以下に、実行するスクリプトを記述していきます。
(17〜18)監視カメラでモーションを検知したら、サウンドをスタートします。
(20)NetConnectionオブジェクト(nc)を使ってリモート共有オブジェクトに接続します。
◆5. サウンドの定義(Startボタン押下後)
監視モニタのStartボタンを押した後の、サウンドの定義をします。
22: StartButton.onRelease = function() {
23: recieveVideo();
24: startSound = function()
{
25: if(isSound == "on") {
26: alertSound.start();
27: } else {
28: alertSound.stop();
29: }
30: };
31: }; |
(24)function以下にサウンドスタートの定義をします。
(25〜30)「on」という値が返ったらサウンドをスタートし、それ以外はサウンドをストップします。
◆6. サウンドの定義(Stopボタン押下後)
監視モニタのStopボタンを押した後の、サウンドの定義をします。
32: StopButton.onRelease = function() {
33: videoBox.attachVideo(null);
34: videoBox.clear();
35: ns.close();
36: alertSound.stop();
37: }; |
(36)サウンドをストップします。
◆7. サウンドの設定
38: function recieveVideo() {
39: ns = new NetStream(nc);
40: ns.play("watching");
41: videoBox.attachVideo(ns);
42: ns.onStatus = function(res)
{
43: if(res.code == "NetStream.Play.UnpublishNotify")
{
44: alertSound.stop();
45: } else if(res.code == "NetStream.Play.PublishNotify")
{
46: alertSound.start();
47: };
48: };
49: } |
(43〜48)返されるパラメータのプロパティコードが「NetStream.Play.UnpublishNotify」の場合、サウンドをストップし、「NetStream.Play.PublishNotify」の場合、サウンドをスタートします。
◆8. 動作確認
3〜7のスクリプトが記述できたら、動作確認をします。[ファイル]メニューから[パブリッシュプレビュー]-[Flash]をクリックして、プレビューします。スクリプトの記述ミスなどで、エラーにならないかどうか確認します。
◆9. 保存とパブリッシュ
FLAファイルに名前を付けて保存し、パブリッシュします。監視モニターには、「monitor_alert」という名前を付けることにします。[ファイル]メニューから「名前を付けて保存」をしてから、[パブリッシュ設定]をします。[形式]タブを開き、[タイプ]のところで「Flash」と「HTML」にチェックマークを入れてオンにして、OKします。設定後に、[ファイル]メニューの[パブリッシュ]を実行すれば、「monitor_alert.fla」と「monitor_alert.swf」、「monitor_alert.html」の3つのファイルができます。
 |
| 3つのファイルができる |
|



|
 |

















|