Tag Archive for 'actionscript3'

28Octflash.text.engine.ElementFormatリサーチ

FlashPlayer10

This movie requires Flash Player 9

FlashPlayer10のflash.text.engine.*が気になったけど、サンプル見つからなかった。
手始めにElementFormatがどんな感じか見てみることに。

ごりごり使うには、オーサリングツール側で調整できるようにならないと現実問題厳しい感じ。
FlashCS4に期待。

25AugActionScript2→3する時に読んどくリンク達

AS3に慣れてきたら、なんで今までこうじゃなかったんだって思ってしまうけど、それが言語というものなんだろうし。
で、AS3初めて触った時、

  • for each
  • trace
  • E4X

の順で感動しましたよ。(使用頻度の問題じゃなくて。)
なんで今までこうじゃなかったんだろう・・・と。

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

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

28MarTweenerの最新バージョン

開発中のTweenerの最新バージョンにはFilterの機能が付いているらしい。
リポジトリのURLとかFilterのレビューしてる方のURLとかをメモっとく。




Return to page top