home > AS3 : SWFAddress

AS3 : SWFAddress

January 19, 2011

progressinを使わず、AS3でSWFAddressを使う方法。

ライブラリは下記より最新のものをDLください。
http://www.asual.com/swfaddress/

イベントの種類
・URLを変更したい場合
SWFAddressEvent.CHANGE
・ページが変わったというイベントが実行される場合
SWFAddressEvent.INTERNAL_CHANGE
・ブラウザの戻るボタンや進むボタンなど、FLASH以外での制御が行われた場合
SWFAddressEvent.EXTERNAL_CHANGE

package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import SWFAddress;
import SWFAddressEvent;
public class SwfaddressCls
{
   private var _defaultTitle:String;
   
   public function SwfaddressCls():void
   {
    //SWFAddress
    SWFAddress.addEventListener(SWFAddressEvent.INIT, initHandler);
   }
   public function clickHandler(_swfname:String):void
   {
    SWFAddress.setValue( _swfname );
    SWFAddress.setTitle( _swfname );
    
    switch(_swfname)
    {
     case "sample1":
      trace("sample1");
      break;
     case "sample2":
      trace("sample2");
      break;
     case "resetStatus()":
      SWFAddress.resetStatus();
      break;
    }
   }
   private function initHandler(event:SWFAddressEvent):void
   {
    SWFAddress.removeEventListener(SWFAddressEvent.INIT, initHandler);
    
    trace("------------------------------------");
    trace("parameterNames: " + event.parameterNames);
    trace("parameters: " + event.parameters);
    trace("path: " + event.path);
    trace("pathNames: " + event.pathNames);
    trace("target: " + event.target);
    trace("type: " + event.type);
    trace("value: " + event.value);
    
    trace("getBaseURL: " + SWFAddress.getBaseURL());
    trace("getHistory: " + SWFAddress.getHistory());
    trace("getParameter: " + SWFAddress.getParameter("unko"));
    trace("getParameterNames: " + SWFAddress.getParameterNames());
    trace("getPath: " + SWFAddress.getPath());
    trace("getPathNames: " + SWFAddress.getPathNames());
    trace("getQueryString: " + SWFAddress.getQueryString());
    trace("getStatus: " + SWFAddress.getStatus());
    trace("getStrict: " + SWFAddress.getStrict());
    trace("getTitle: " + SWFAddress.getTitle());
    trace("getTracker: " + SWFAddress.getTracker());
    trace("getValue: " + SWFAddress.getValue());
    trace("------------------------------------");
    
    _defaultTitle = SWFAddress.getTitle();
    
    SWFAddress.addEventListener(SWFAddressEvent.CHANGE, changeHandler);
    SWFAddress.addEventListener(SWFAddressEvent.EXTERNAL_CHANGE, externalChangeHandler);
    SWFAddress.addEventListener(SWFAddressEvent.INTERNAL_CHANGE, internalChangeHandler);
  }
  private function changeHandler(event:SWFAddressEvent):void
  {
    trace("------------------------------------");
    // パラメータのキー名一覧を配列で取得
    trace("parameterNames: " + event.parameterNames);
    // パラメータ全てを連想配列(Object 型)で取得
    trace("parameters: " + event.parameters);
    // SWFAddress の path 文字列(#以降の文字列)を取得する
    trace("path: " + event.path);
    // SWFAddress の path を配列で取得
    trace("pathNames: " + event.pathNames);     trace("target: " + event.target);
    trace("type: " + event.type);
    trace("value: " + event.value);
    
    switch(event.value)
    {
     case "/sample1":
      trace("sample1");
      Action(sample1);
      break;
     case "/sample2":
      trace("sample2");
      Action(sample2);
      break;
    }
  }
  private function externalChangeHandler(event:SWFAddressEvent):void
  {
    trace("------------------------------------");
    // パラメータのキー名一覧を配列で取得
    trace("parameterNames: " + event.parameterNames);
    // パラメータ全てを連想配列(Object 型)で取得
    trace("parameters: " + event.parameters);
    // SWFAddress の path 文字列(#以降の文字列)を取得する
    trace("path: " + event.path);
    // SWFAddress の path を配列で取得
    trace("pathNames: " + event.pathNames);
    trace("target: " + event.target);
    trace("type: " + event.type);
    trace("value: " + event.value);
  }
  private function internalChangeHandler(event:SWFAddressEvent):void
  {
    trace("------------------------------------");
    // パラメータのキー名一覧を配列で取得
    trace("parameterNames: " + event.parameterNames);
    // パラメータ全てを連想配列(Object 型)で取得
    trace("parameters: " + event.parameters);
    // SWFAddress の path 文字列(#以降の文字列)を取得する
    trace("path: " + event.path);
    // SWFAddress の path を配列で取得
    trace("pathNames: " + event.pathNames);
    trace("target: " + event.target);
    trace("type: " + event.type);
    trace("value: " + event.value);
  }
 }
}

参考サイトはこちら
http://feb19.jp/blog/archives/000181.php



ブックマークする hatena del.ico.us


Comments

Post a Comment






Remember personal info