一般的なソフトウェア、デスクトップアプリケーションでもWeb系アプリケーションでも、マイクロソフトのWindowsも同じでバージョンの自動更新機能があります。
ユーザさんたちはわざわざソフトウェアのホームページにアクセス必要がなくて、ソフトウェアを起動するとき、
自動的で新しいバージョンがあるかどうかチェックして、あれば更新するかどうか確認メッセージを出るのはカッコいいですね。
そのような機能、Flex中にはどう実装するはずですか。以下は実装の詳細です。
1)、必要なバージョンなど情報をプロパティファイルに書く
- #Each item takes the same params as the ContextMenuItem class
- #caption:String = caption Value : String,
- #separatorBefore:Boolean = false,
- #enabled:Boolean = true,
- #visible:Boolean = true
- #In addition each item supports a url variable just add
- #&YOUR URL GOES HERE;
- Version=Version 0.1&false&false&true;
- url=Developer : DigiTechlog&false&true&true&http://digitechlog.com
- viewSource=View Source&false&true&true&http://digitechlog.com/ext/VersionControl/srcview/
2)、自分のプロジェクトへ以下のソース(VersionControl.as)を追加とする
- package VersionControl
- {
- import flash.events.ContextMenuEvent;
- import flash.net.URLRequest;
- import flash.net.navigateToURL;
- import flash.ui.ContextMenu;
- import flash.ui.ContextMenuItem;
- import flash.utils.Dictionary;
- import mx.core.Application;
- import mx.core.UIComponent;
- import mx.core.mx_internal;
- import mx.resources.ResourceBundle;
- use namespace mx_internal;
- public class VersionController extends Application
- {
- [ResourceBundle( 'VersionControl' )]
- private static var _rb : ResourceBundle;
- private static var _rbi : Dictionary;
- private static function update( ) : void
- {
- // super.updateDisplayList( unscaledWidth, unscaledHeight );
- _rbi = new Dictionary( );
- var rbi : Object = _rb.content;
- var cm : ContextMenu = new ContextMenu( );
- for( var i : String in rbi )
- {
- var properties : Array = String( rbi[ i ] ).split( '&' );
- var value : String = properties[ 0 ];
- var separator : Boolean = properties[ 1 ] ? properties[ 1 ] == 'false' ? false : true : true;
- var enabled : Boolean = properties[ 2 ] ? properties[ 2 ] == 'false' ? false : true : true;
- var visible : Boolean = properties[ 3 ] ? properties[ 3 ] == 'false' ? false : true : true;
- var open : Boolean = properties[ 4 ] ? properties[ 4 ] == 'false' ? false : true : true;
- var cmi : ContextMenuItem = new ContextMenuItem( value, separator, enabled, visible );
- cm.customItems.push( cmi );
- cm.hideBuiltInItems( );
- if( open )
- {
- cmi.addEventListener( ContextMenuEvent.MENU_ITEM_SELECT, openWindow );
- _rbi[ value ] = properties[ 4 ] ? properties[ 4 ] : 'http://www.betadesigns.co.uk/Blog';
- }
- }
- _application.contextMenu = cm;
- }
- private static function openWindow( e : ContextMenuEvent ) : void
- {
- navigateToURL( new URLRequest( _rbi[ e.target.caption ] ), "_blank" );
- }
- /**
- * Forces this class to use the singleton pattern;
- *
- */
- private static var _class : VersionController;
- private static var _application : UIComponent;
- public static function getInstance( item :UIComponent ) : VersionController
- {
- _application = item;
- if( !_class )
- _class = new VersionController( new SingletonEnforcer( ) );
- update( );
- return _class;
- }
- public function VersionController( se : SingletonEnforcer )
- {
- //can Never get here without calling getInstance( );
- }
- }
- }
- class SingletonEnforcer{ }
3)、下記のようなMXMLで使う
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
- creationComplete="VersionController.getInstance( this )"
- xmlns:CustomColorPickerComponent="uk.co.BetaDesigns.components.CustomColorPickerComponent.*" viewSourceURL="srcview/index.html">
- <mx:Script>
- <![CDATA[
- import VersionControl.VersionController;
- ]]>
- </mx:Script>
- </mx:Application>
メインコンテンツEND ■
Posted on Monday, 24th November 2008 by admin
Tags: Flex, サンプル, バージョン, ライブラリ
Posted in Flex | Comments (1) | 1,484 views

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