一般的なソフトウェア、デスクトップアプリケーションでもWeb系アプリケーションでも、マイクロソフトのWindowsも同じでバージョンの自動更新機能があります。

ユーザさんたちはわざわざソフトウェアのホームページにアクセス必要がなくて、ソフトウェアを起動するとき、

自動的で新しいバージョンがあるかどうかチェックして、あれば更新するかどうか確認メッセージを出るのはカッコいいですね。

そのような機能、Flex中にはどう実装するはずですか。以下は実装の詳細です。

1)、必要なバージョンなど情報をプロパティファイルに書く


  1. #Each item takes the same params as the ContextMenuItem class
  2. #caption:String = caption Value : String,
  3. #separatorBefore:Boolean = false,
  4. #enabled:Boolean = true,
  5. #visible:Boolean = true
  6. #In addition each item supports a url variable just add
  7. #&YOUR URL GOES HERE;
  8. Version=Version 0.1&false&false&true;
  9. url=Developer : DigiTechlog&false&true&true&http://digitechlog.com
  10. viewSource=View Source&false&true&true&http://digitechlog.com/ext/VersionControl/srcview/

2)、自分のプロジェクトへ以下のソース(VersionControl.as)を追加とする

  1. package VersionControl
  2. {
  3.     import flash.events.ContextMenuEvent;
  4.     import flash.net.URLRequest;
  5.     import flash.net.navigateToURL;
  6.     import flash.ui.ContextMenu;
  7.     import flash.ui.ContextMenuItem;
  8.     import flash.utils.Dictionary;
  9.    
  10.     import mx.core.Application;
  11.     import mx.core.UIComponent;
  12.     import mx.core.mx_internal;
  13.     import mx.resources.ResourceBundle;       
  14.     use namespace mx_internal;
  15.  
  16.     public class VersionController extends Application
  17.     {
  18.  
  19.         [ResourceBundle( 'VersionControl' )]
  20.         private static var _rb     : ResourceBundle;
  21.        
  22.         private static var _rbi : Dictionary;
  23.  
  24.         private static function update(  ) : void
  25.         {
  26.         //    super.updateDisplayList( unscaledWidth, unscaledHeight );
  27.             _rbi = new Dictionary( );
  28.             var rbi : Object = _rb.content;
  29.             var cm : ContextMenu = new ContextMenu( );
  30.             for( var i : String in rbi )
  31.             {
  32.                 var properties     : Array = String( rbi[ i ] ).split( '&' );
  33.                 var value         : String = properties[ 0 ];
  34.                 var separator     : Boolean = properties[ 1 ] ? properties[ 1 ] == 'false' ? false : true : true;
  35.                 var enabled        : Boolean = properties[ 2 ] ? properties[ 2 ] == 'false' ? false : true : true;
  36.                 var visible        : Boolean = properties[ 3 ] ? properties[ 3 ] == 'false' ? false : true : true;
  37.                 var open        : Boolean = properties[ 4 ] ? properties[ 4 ] == 'false' ? false : true : true;
  38.                 var cmi : ContextMenuItem = new ContextMenuItem( value, separator, enabled, visible );
  39.                     cm.customItems.push( cmi );
  40.                     cm.hideBuiltInItems( );           
  41.                 if( open )
  42.                 {
  43.                     cmi.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, openWindow );
  44.                     _rbi[ value ] = properties[ 4 ] ? properties[ 4 ] : 'http://www.betadesigns.co.uk/Blog';           
  45.                 }
  46.             }
  47.             _application.contextMenu = cm;
  48.         }
  49.        
  50.  
  51.         private static function openWindow( e : ContextMenuEvent ) : void
  52.         {
  53.             navigateToURL( new URLRequest( _rbi[ e.target.caption ] ), "_blank" );
  54.         }
  55.  
  56.  
  57.         /**
  58.         * Forces this class to use the singleton pattern;
  59.         *
  60.         */
  61.         private static var _class         : VersionController;
  62.         private static var _application    : UIComponent;
  63.         public static function getInstance( item :UIComponent  )VersionController
  64.         {
  65.             _application = item;
  66.             if( !_class )
  67.                 _class = new VersionController( new SingletonEnforcer( ) );
  68.                
  69.                 update( );
  70.  
  71.             return _class;
  72.         }
  73.         public function VersionController( se : SingletonEnforcer )
  74.         {
  75.             //can Never get here without calling getInstance( );
  76.         }
  77.     }
  78. }
  79. class SingletonEnforcer{ }

3)、下記のようなMXMLで使う

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
  3.     creationComplete="VersionController.getInstance( this )" 
  4.     xmlns:CustomColorPickerComponent="uk.co.BetaDesigns.components.CustomColorPickerComponent.*" viewSourceURL="srcview/index.html">
  5.     <mx:Script>
  6.         <![CDATA[
  7.             import VersionControl.VersionController;
  8.         ]]>
  9.     </mx:Script>
  10. </mx:Application>
メインコンテンツEND ■
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Posted on Monday, 24th November 2008 by admin

Tags: , , ,
Posted in Flex | Comments (1) | 1,484 views

One Response to “Flexアプリケーションにバージョンコントロールを実装するライブラリとサンプルソース”

  1. Flexアプリケーションにマルチ言語対応(サンプルソースコード添付) | DigiTechLog Dot Com Says:

    [...] この前紹介した「Flexアプリケーションにバージョンコントロールを実装するライブラリとサンプルソース」のバージョンコントロールと同じ、アプリケーションのマルチ言語対応も重要 [...]

Leave a Reply