Adobe AIRをFlashで作成していてオンラインかオフライン
か常に監視させて確認さる処理に使ったときのメモひらめき電球

ネットワーク接続の監視を参考にすると分かりやすいです。

コンポーネント AIR ServiceMonitor の
ServiceMonitorShim.swc をステージに配置
して

import air.net.*;

をする必要があります。

CS4の場合は、ServiceMonitorShim.swc の設定が微妙に違います。
ファイル-パブリッシュ設定 -> Flashパネル -> ActionScript3.0設定
からライブラリパスを選択して、servicemoniter.swcを選択。

//オンラインかオフラインかを判別 常時監視
function onURLStatusCheckTimer(e:StatusEvent):void {
//オンライン true でオンライン falseでオフライン
trace(e.target.available);
}

//ネットワークの監視
function networkMonitorCheckTimer(e:TimerEvent):void {
var request:URLRequest = new URLRequest("http://ameblo.jp/linking/");
var monitor:URLMonitor = new URLMonitor(request);

monitor.addEventListener(StatusEvent.STATUS, onURLStatusCheckTimer);
monitor.start();
}

//タイマー3秒に一回ずつ実行
function netCheckTimerStart():void {
var timer:Timer = new Timer(3000);

timer.addEventListener(TimerEvent.TIMER, networkMonitorCheckTimer);
timer.start();
}


オンラインかオフラインかを常に監視させる方法でなく
ネットワークの監視変更があった場合に実行させる
ようにすることもできます。

AIRでは、ネットワークの確認を使う機会が多い
のではないかなぁと思います。
前からグーグルマップで地図にルート案内を付けたかった
のでこの情報はありがたいですひらめき電球

Google Map APIでルート表示をする

ルートポイントの指定
function plotRoute(overlay, latlng) {
// Create a new marker based on the coordinates
var marker = new GMarker(latlng);

// Instantiate the GDirections class
var directions = new GDirections(map);

// Add the new marker to the map
map.addOverlay(marker);

// Create the new array element
coordinates_array_element = latlng.lat() + "," + latlng.lng();

// Add the new array element to the map
coordinates.push(coordinates_array_element);

// If > one point on the map, plot the route between these two points
if (coordinates.length > 1) {
directions.loadFromWaypoints(coordinates);
}
}

呼び出し
GEvent.addListener(map, "click", plotRoute);


高速道路を回避したり、地点から次の地点まで
ユーザーに道案内を表示したり、距離の移動時間
を計算する方法も紹介されているので参考になりますニコニコ

Google Map APIでルート表示をする
phpで日付の計算をしていて特定の日付から
何日間あるのか簡単に調べる方法を探して
いたらよいやり方を発見ひらめき電球

結構遠回りなやり方をしていたので
このテクニックは覚えておきますニコニコ

PHP ふたつの日付から何日間離れているか調べる

ふたつの日付「2008-01-10」「2008-03-14」が何日間離れているか調べる
//日付をセット
$pDate1 = '2008-01-10';
$pDate2 = '2008-03-14';

//日付をUNIXタイムスタンプに変換
$TimeStamp1 = strtotime($pDate1);
$TimeStamp2 = strtotime($pDate2);

//何秒離れているかを計算(絶対値)
$SecondDiff = abs($TimeStamp2 - $TimeStamp1);

//日数に変換
$DayDiff = $SecondDiff / (60 * 60 * 24);

//出力
echo $DayDiff . '日間離れています';



日付の計算や時間の比較などは、手間だし手抜き処理をすると
バグになるので大変なんですよねあせる
これは関数にして日数を取得できるように
しておくと便利ですね。