Tag Archive for 'flex'

19OctIEでTextInputにCtrl+Enterで改行されるバグ

IE6/7で確認。

This movie requires Flash Player 9

上はFlexで書き出したSWFだけど、Flashの入力可能な単一行のTextFieldでも同様の動作。
IEの独自機能のショートカットとFlashPlayerの競合だと思うけど、いつまで放置してるんでしょう。

改行を削除しようにも改行が追加されたタイミングを、Event.CHANGEやFlexEvent.VALUE_COMMITで取得できないので、泥臭く消すしかないっていう。

Web内見回してみたところ、処理してるとこの方が少ないから気づかなかったってことでいいですか?

17JulBlazeDS - Messaging(Client)

BlazeDSの主要な機能の一つであるMessegingのクライアントサイドの処理について。

  1. srcを右クリックして、「新規 > MXML アプリケーション」をクリック。「ファイル名」をmessaging.mxmlと入力して「終了」。

    ss_032 ss_033
  2. クライアントの処理を書く。

    ss_034
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()" viewSourceURL="srcview/index.html">
    3.    
    4.     <mx:Script>
    5.         <![CDATA[
    6.             import mx.messaging.events.MessageFaultEvent;
    7.             import mx.messaging.messages.AsyncMessage;
    8.             import mx.messaging.messages.IMessage;
    9.             import mx.messaging.ChannelSet;
    10.             import mx.messaging.channels.AMFChannel;
    11.             import mx.messaging.channels.StreamingAMFChannel;
    12.             import mx.messaging.events.MessageEvent;
    13.             import mx.messaging.events.ChannelEvent;
    14.             import mx.messaging.Consumer;
    15.             import mx.messaging.Producer;
    16.            
    17.             private var producer:Producer = new Producer();
    18.             private var consumer:Consumer = new Consumer();
    19.            
    20.             private function init():void {
    21.                 initConnectEvent();
    22.                
    23.                 connectToServer();
    24.             }
    25.            
    26.             private function initConnectEvent():void {
    27.                 consumer.addEventListener(ChannelEvent.CONNECT, hdlConsumerConnect);
    28.                 consumer.addEventListener(ChannelEvent.DISCONNECT, hdlConsumerDisconnect);
    29.                 consumer.addEventListener(MessageEvent.MESSAGE, hdlConsumerMessage);
    30.             }
    31.            
    32.             private function hdlConsumerConnect(ce:ChannelEvent):void {
    33.                 log("Connect to Server.");
    34.                
    35.                 setSend(true);
    36.             }
    37.            
    38.             private function hdlConsumerDisconnect(ce:ChannelEvent):void {
    39.                 log("Disconnect from Server.");
    40.                
    41.                 setSend(false);
    42.             }
    43.            
    44.             private function hdlConsumerMessage(me:MessageEvent):void {
    45.                 log(me.message.body.chat);
    46.             }
    47.            
    48.             private function setSend(bln:Boolean):void {
    49.                 if (bln) {
    50.                     btnSend.addEventListener(MouseEvent.CLICK, hdlSendClick);
    51.                 } else {
    52.                     btnSend.removeEventListener(MouseEvent.CLICK, hdlSendClick);
    53.                 }
    54.                 btnSend.enabled = bln;
    55.                 tiChat.enabled = bln;
    56.             }
    57.            
    58.             private function hdlSendClick(e:*):void {
    59.                 var msg:IMessage = new AsyncMessage();
    60.                 msg.body = {chat:tiChat.text};
    61.                
    62.                 producer.send(msg);
    63.                 tiChat.text = "";
    64.             }
    65.            
    66.             private function connectToServer():void {
    67.                 setChannel("localhost");
    68.                 setDistination();
    69.                
    70.                 consumer.subscribe();
    71.             }
    72.            
    73.             private function setChannel(hostname:String):void {
    74.                 var channelSet:ChannelSet = new ChannelSet();
    75.                 var myStreamingAMF:AMFChannel = new StreamingAMFChannel("my-streaming-amf", "http://" + hostname + ":8400/tutorial/messagebroker/streamingamf");
    76.                 var myPollingAMF:AMFChannel = new AMFChannel("my-polling-amf", "http://" + hostname + ":8400/tutorial/messagebroker/amfpolling");
    77.                 myPollingAMF.pollingEnabled = true;
    78.                 myPollingAMF.pollingInterval = 1;
    79.                
    80.                 channelSet.addChannel(myStreamingAMF);
    81.                 channelSet.addChannel(myPollingAMF);
    82.                
    83.                 producer.channelSet = channelSet;
    84.                 consumer.channelSet = channelSet;
    85.             }
    86.            
    87.             private function setDistination():void {
    88.                 producer.destination = "messagingTutorial";
    89.                 consumer.destination = "messagingTutorial";
    90.             }
    91.            
    92.             private function log(str:String):void {
    93.                 taLog.text = str + "\n" + taLog.text;
    94.             }
    95.            
    96.         ]]>
    97.     </mx:Script>
    98.    
    99.     <mx:ApplicationControlBar width="100%" height="100%">
    100.         <mx:TextArea width="100%" height="100%" id="taLog" editable="false"/>
    101.     </mx:ApplicationControlBar>
    102.     <mx:ApplicationControlBar width="100%">
    103.         <mx:TextInput id="tiChat" width="100%" enabled="false" enter="hdlSendClick(event)"/>
    104.         <mx:Button label="Send" id="btnSend" enabled="false"/>
    105.     </mx:ApplicationControlBar>
    106.    
    107. </mx:Application>
  3. 「ファイル > エクスポート」をクリックして、「Flex Builder > リリースビルド」を選択して「次へ」。
    「書き出し先フォルダ」をtutorialにして「終了」。

    ss_035 ss_036 ss_037
  4. ブラウザを二窓開いてhttp://localhost:8400/tutorial/messaging.htmlへアクセス。
    一方の窓でテキストを入力し、Sendを押すと、両方のクライアントにストリーミングでテキストが配信される。

    ss_038 ss_039

17JulBlazeDS - Messaging(Server)

BlazeDSの主要な機能の一つであるMessegingのサーバーサイドの処理について。

  1. services-config.xmlにstreamingの設定を書く。

    ss_030
    • XML
    • services-config.xml
    • Source
    1. <?xml version="1.0" encoding="UTF-8"?>
    2.  
    3. <service id="message-service" class="flex.messaging.services.MessageService">
    4.    
    5.     <adapters>
    6.         <adapter-definition id="actionscript" class="flex.messaging.services.messaging.adapters.ActionScriptAdapter" default="true" />
    7.         <!-- <adapter-definition id="jms" class="flex.messaging.services.messaging.adapters.JMSAdapter"/> -->
    8.     </adapters>
    9.    
    10.     <default-channels>
    11.         <channel ref="my-streaming-amf"/>
    12.     </default-channels>
    13.    
    14.     <destination id="messagingTutorial"/>
    15.    
    16. </service>
  2. messaging-config.xmlにデフォルトチャンネルの設定、サービスのIDを書く。

    ss_031
    • XML
    • messaging-config.xml
    • Source
    1. <channel-definition id="my-streaming-amf" class="mx.messaging.channels.StreamingAMFChannel">
    2.     <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/streamingamf" class="flex.messaging.endpoints.StreamingAMFEndpoint"/>
    3.     <properties>
    4.         <idle-timeout-minutes>0</idle-timeout-minutes>
    5.         <max-streaming-clients>100</max-streaming-clients>
    6.         <server-to-client-heartbeat-millis>5000</server-to-client-heartbeat-millis>
    7.         <user-agent-settings>
    8.             <user-agent match-on="MSIE" kickstart-bytes="2048" max-streaming-connections-per-session="10"/>
    9.             <user-agent match-on="Firefox" kickstart-bytes="2048" max-streaming-connections-per-session="10"/>
    10.             <user-agent match-on="AppleWebKit" kickstart-bytes="2048" max-streaming-connections-per-session="10"/>
    11.         </user-agent-settings>
    12.     </properties>
    13. </channel-definition>
  3. サーバーを再起動。

08JulBlazeDS - Remotoing(Client)

BlazeDSの主要な機能の一つであるRemotingのクライアントサイドの処理について。

  1. 「ファイル > 新規 > MXML アプリケーション」をクリックして、「ファイル名」にRemoting.mxmlと入力して、「終了」。

    ss_023 ss_024
  2. remoting.mxmlにクライアントの処理を書く。

    • ActionScript
    • remoting.mxml
    • Source
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" initialize="init()" viewSourceURL="srcview/index.html">
    3.    
    4.     <mx:Script>
    5.         <![CDATA[
    6.             import mx.rpc.remoting.RemoteObject;
    7.             import mx.rpc.events.ResultEvent;
    8.             import mx.rpc.events.FaultEvent;
    9.            
    10.             private var remoteObject:RemoteObject = new RemoteObject();
    11.            
    12.             private function init():void {
    13.                 initRemoteObject();
    14.                 initButtons();
    15.             }
    16.            
    17.             private function initRemoteObject():void {
    18.                 remoteObject.destination = "remotingTutorial";
    19.                 remoteObject.addEventListener("result", hdlROResult);
    20.                 remoteObject.addEventListener("fault", hdlROFault);
    21.             }
    22.            
    23.             private function hdlROResult(re:ResultEvent):void {
    24.                 var result:int = re.message.body.result;
    25.                 setResult(result.toString());
    26.             }
    27.            
    28.             private function hdlROFault(fe:FaultEvent):void {
    29.                 setResult("Fail to get responce.");
    30.             }
    31.            
    32.             private function setResult(str:String):void {
    33.                 tiResult.text = str;
    34.             }
    35.            
    36.             private function initButtons():void {
    37.                 btnCalc.addEventListener(MouseEvent.CLICK, hdlGetCalcClick);
    38.                 btnClear.addEventListener(MouseEvent.CLICK, hdlClearClick);
    39.                
    40.                 btnCalc.enabled = true;
    41.                 btnClear.enabled = true;
    42.             }
    43.            
    44.             private function hdlGetCalcClick(me:MouseEvent):void {
    45.                 var obj:Object = new Object();
    46.                
    47.                 obj.param0 = int(tiParam_0.text);
    48.                 obj.param1 = int(tiParam_1.text);
    49.                
    50.                 remoteObject.getCalcResult(obj);
    51.             }
    52.            
    53.             private function hdlClearClick(me:MouseEvent):void {
    54.                 setResult("");
    55.             }
    56.            
    57.         ]]>
    58.     </mx:Script>
    59.    
    60.     <mx:ApplicationControlBar>
    61.         <mx:TextInput id="tiParam_0" text="10"/>
    62.         <mx:Label text="+" textAlign="center"/>
    63.         <mx:TextInput id="tiParam_1" text="20"/>
    64.         <mx:Label text="=" textAlign="center"/>
    65.         <mx:TextInput id="tiResult"/>
    66.     </mx:ApplicationControlBar>
    67.     <mx:ApplicationControlBar>
    68.         <mx:Button label="getCalcResult" id="btnCalc" enabled="false"/>
    69.         <mx:Button label="clear" id="btnClear" enabled="false"/>
    70.     </mx:ApplicationControlBar>
    71.    
    72. </mx:Application>
    ss_025
  3. 「ファイル > エクスポート」より、「Flex Builder > リリースビルド」を選択して「次へ」。「書き出し先フォルダ」をtutorialにして、「終了」。

    ss_026 ss_027 ss_028
  4. これで、クライアントの開発は完了。ブラウザでhttp://localhost:8400/tutorial/remoting.htmlにアクセスして確認。

    ss_029

07JulBlazeDS - Remotoing(Server)

BlazeDSの主要な機能の一つであるRemotingのサーバーサイドの処理について。

  1. remoting-config.xmlで、これから使うRemotingのサービスを定義する。 <destination id="***">には、クライアントからサーバーサイドJavaのメソッドを呼び出すときのユニークなIDを入力。 <source>***</source>には、サーバーサイドJavaのパッケージ名.クラス名を入力。

    • XML
    • remoting-config.xml
    • Source
    1. <destination id="remotingTutorial">
    2.     <properties>
    3.         <source>tutorial.RemotingTutorial</source>
    4.         <scope>application</scope>
    5.     </properties>
    6. </destination>
    ss_010
  2. 「ファイル > 新規 > プロジェクト」より、「Javaプロジェクト」を作成する。

    ss_011 ss_012
  3. 「内容 > 外部ソースからプロジェクトを作成」をチェックし、\tutorial\WEB-INF\classesを指定し、「次へ」。

    ss_013 
  4. 「ライブラリー > 外部JARの追加」で、\tutorial\WEB-INF\lib内の全jarファイルを指定し、クラスパスを通す。

    ss_014 ss_015 ss_016
  5. tutorial-javaを右クリックして、「新規 > パッケージ」をクリック。「名前」に1.で設定したパッケージ名(このチュートリアルでは"tutorial")を入力して「終了」。

    ss_017 ss_018
  6. \tutorial\WEB-INF\srcに1.で設定したクラス名のJavaのソースファイルを作る。(このチュートリアルでは"RemotingTutorial.java)

    ss_019
  7. 6.で作ったクラスファイル(RemotingTutorial.java)を、5.で作ったパッケージ内にリンクする。tutorialを右クリックして、「新規 > ファイル」をクリック。「拡張」をクリック後、6.で作ったクラスファイルを指定し、終了。

    ss_020 ss_021
  8. RemotingTutorial.javaを開き、足し算して返すだけの関数を書く。

    • Java
    • RemotingTutorial.java
    • Source
    1. package tutorial;
    2.  
    3. import java.util.HashMap;
    4.  
    5. public class RemotingTutorial {
    6.    
    7.     public RemotingTutorial() {
    8.         System.out.println("RemotingTutorial を初期化します");
    9.     }
    10.    
    11.     public HashMap<String, Integer> getCalcResult(HashMap<String, Integer> mapSource) {
    12.         HashMap<String, Integer> mapBody = new HashMap<String, Integer>();
    13.        
    14.         mapBody.put("result", (mapSource.get("param0") + mapSource.get("param1")));
    15.        
    16.         return mapBody;
    17.     }
    18.    
    19. }
    ss_022



Return to page top