2012年3月23日 星期五

AMFPHP研究 : Flash Flex 跟AMFPHP使用

1.amfphp 2.0.1 http://www.silexlabs.org/amfphp/ 下載與教學 (幾個月沒用了 現在已經變成2.1哩)

2.隨便一個可以架站的網站 讓http://localhost/amfphp/Amfphp/index.php 可以找的到即可

在windows下 我是使用appServer 比較簡單易懂
在macos下 我是使用MANP

















3.介紹兩個方式

一個是使用flash NetConnect

一個是使用flex RemoteObject

A.php端


1.建置一個HelloWorld.php
內容如下


<?php
class HelloWorld
{
    function sayHello()
    {
        return "Hello World!";
    }
}
?>



2.放到資料夾C:\AppServ\www\amfphp\Amfphp\Services 下

3.測試網址http://localhost/amfphp/Amfphp 點選 if you are looking for service browser .....

有出現你放上去的class 還可以測試 就代表你成功了
一般會失敗的原因就是.php file沒有放在 Amfphp/Service下













B.Flash端 


 1.用flash cs 開啟一個fla吧

2.寫script
import flash.net.*;

var con:NetConnection = new NetConnection ;// 新增一個NetConnection物件

var re:Responder = new Responder(onResult,onFault); // 連上AMF gateway

con.connect("http://127.0.0.1/amfphp/Amfphp/index.php");

/*切記要加上 /index.php 
因為他不像flex 只指定http://127.0.0.1/amfphp/Amfphp/ 就好了
不然會一直卡在Error #2044: Unhandled NetStatusEvent:. level=error,code=NetConnection.Call.BadVersion
                  at Untitled_fla::MainTimeline/frame1()
*/
function onResult(result:Object):void {                                            //資料傳送成功時
    var saveData:Object=result;
    trace(saveData);
}
function onFault(fault:Object):void {                                                        //資料傳送失敗時
    trace("failt");
}
con.call("HelloWorld.sayHello",re);

3.即可以看到php裡return Hello World ! (代表成功哩)


C.flex端


1.開啟flash builder new 一個project起來

2.在src 裡 設定services-config.xml

內容如下
<?xml version="1.0" encoding="utf-8"?>
<services-config>
<services>
<service id="amfphp-flashremoting-service" 
class="flex.messaging.service.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage">
<destination id="amfphp">
<channels>
<channel ref="my-amfphp" />
</channels>
<properties>
<source>*
</source>
</properties>
</destination>
</service>
</services>
<channels>
<channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://127.0.0.1/amfphp/Amfphp/" class="flex.messaging.endpoints.AMFEndpoint" /></channel-definition>
</channels>
</services-config>
一般都是 http://127.0.0.1/amfphp/Amfphp/ 修改一下 就好了

3.選取Project > Properties > Flex Compiler > Additional compiler arguments 下添加

如圖












4.mxml內容如下:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      minWidth="955"
      minHeight="600">
 <s:layout>
  <s:BasicLayout/>
 </s:layout>
 <fx:Script>
  <![CDATA[
   import mx.managers.CursorManager;
   import mx.rpc.events.ResultEvent;
   import mx.rpc.events.FaultEvent;

   private function faultHandler(fault:FaultEvent):void
   {
    CursorManager.removeBusyCursor();
    result_text.text="code:\n" + fault.fault.faultCode + "\n\nMessage:\n" + fault.fault.faultString + "\n\nDetail:\n" + fault.fault.faultDetail;
   }

   private function resultHandler(evt:ResultEvent):void
   {
    trace("success");
    result_text.text+=evt.message.body.toString() + "\n"; // same as: evt.result.toString();
   }
  ]]>
 </fx:Script>
 <fx:Declarations>
  <mx:RemoteObject id="myservice"
       fault="faultHandler(event)"
       showBusyCursor="true"
       source="HelloWorld"
       destination="amfphp">
   <mx:method name="sayHello"
        result="resultHandler(event)"/>
  </mx:RemoteObject>
 </fx:Declarations>
 <mx:Button x="250"
      y="157"
      label="sayHello"
      width="79"
      click="myservice.getOperation('sayHello').send();"/>
 <mx:Button x="250"
      y="187"
      label="test fault"
      click="myservice.getOperation('foo').send(); "/>
 <mx:TextArea x="10"
     y="36"
     width="319"
     height="113"
     id="result_text"/>
 <mx:Label x="10"
     y="10"
     text="Result:"/>
</s:Application>

5. run 起來 即可測試看看 是否有收到Hello World !

source code

//使用flash cs6
https://github.com/evonda/testAMFPHP

//使用flash builder 4.6 匯入
https://github.com/evonda/testFlexAmfphp

2012年3月22日 星期四

Flex 4 真的實作囉 by diabee

在本公司應該算是最後一個作品了"播牌的技術" 這次我會開始使用flex的技術了 就不再去掛羊頭賣狗肉勒(用flex寫as3) ~
等我好消息 ~~

BOX2D研究心得

記得剛進公司的時候,當時就是在學東西,所以有碰過一下BOX2D,不過這次卻看到一個前備在開發的時候既然使用過他,欣喜若狂,我開始研究一下吧:D
http://www.box2dflash.org/docs/2.0.2/manual#Box2D_v2.0.1_User_Manual

2012年3月8日 星期四

scaleform 的心得

最近再研究 autodest scaleform ~

..........
..........
..........





這套UI介面話說 是把flash 加到一個C/C++遊戲開發 的領域裡 讓UI設計得更頗為方便 ~

但是 這玩意 我品藏了兩天 ~

還真的從C++ 下手 才可以全盤掌握 ~ 或許這是 for c/c++開發員所設計的工具吧 ~

假如我從flash的經驗 下去著手 遇到的問題都是莫名奇妙的

問題:

1. flash 寫法 萬萬種 ~ 但是哪一種才是exactly coding ~(這個問題又偏及到美術設計的程面) 唉 我慢慢像是一個desginer

2. vs的操作 顧名思義 你對C++ 一定要有一定程度 再去碰會比較實際點 ~ (乾 這個IDE到底是有多好用啦 怎麼一推人用)

3. 未來還有諸多問題要討論 ~( 但是討論的都是偏於人性方面的思考 並非技術上的思考 這點真的要很難適應)

by 技術沉默的阿B

總結一句話: 唉 這是工作 !!

2012年2月15日 星期三

air auto update

環境 : flash builder 4.5(FB) // air sdk 3.0  // appserv 可以架個server抓到update.xml和.air安裝檔 即可
測試 1.0.0(原始安裝檔) 透過指定.xml ==更新==> 1.0.1(之後的更新版本)
專案測試名稱 : testAutoPatch

1.在專案的建置過程中跟一般FB開設專案一樣

2.設定testAutoPatch-app.xml
FB會自動幫你生成testAutoPatch-app.xml
來看裡面的內容吧
找到versionnumber 這個tag
並設定他的版號1.0.0
看你的設計方式 1.0 也可

ps: 這個代表當專案release 的時候 所給予他的版號  將來都會根據這個為依據 去參考update.xml 去check是否要更新你的專案

3. src 下設計一個configuration.xml
內容如下:
<configuration xmlns="http://ns.adobe.com/air/framework/update/configuration/1.0">  <url>http://localhost/update.xml</url>  
<delay>1</delay> 
<dialog name="checkForUpdate" visible="false"/>
<dialog name="downloadUpdate" visible="true"/>
<dialog name="downloadProgress" visible="true"/>         
<dialog name="installUpdate" visible="true"/> 
</configuration> 
configuration xmlns 主要是定義這個adobe auto update configuration , 版本 1.0 (非我們使用的air sdk 的3.0 喔 , 我在這裡卡住過)


http://localhost/update.xml 參考update.xml的依據 (之後會講這個內容)

The delay property 是定期檢查update之間的delay時間 參數(day);
defaultUI :

checkForUpdate : 開起來就會執行update , 就算你沒有update 都會跳一個dialog出來 ;
downloadUpdate : 下載Update dialog box
downloadProgress : 下載Progress dialog box
installUpdate : install update dialog box

ps: 還有不需要建置configuration.xml 去設計這個air auto update 其實大同小異 方式都差不多

4.release 出來 此就為最新的 1.0.0 的testAutoPatch.air install file (此為原始發佈給使用者用的.air)

========================================================================
web簡易設計

5.有版本上的控制的人 其實會常常把release 出來的  .air 安裝檔 放入server 上 ~ 也會順便去更新這個update.xml  (其實就有點web service的意思了 在這裡就不詳述這個細節勒 因為做法很多)

1.0.1
http://192.168.106.93/AutoUpdate/testAutoPatch.air



versionNumber : 這個最主要就是要描述http://localhost/AutoUpdate/testAutoPatch.air 的版本是多少
url : release 出來 .air 的位置
description : 此版本的新增描述

6. 這裡我是使用appServ去架一個簡單的http server ~ 把未來發布出來的testAutoPatch.air和update.xml 放到指定的目錄 , 以供程式執行的時候會自動去check update

========================================================================

7.撰寫基本的testAutoPatch.mxml


 
  
  
 
 
  
 
 
  
 


//使用ApplicationUpdateUI 套件

private var _updater:ApplicationUpdaterUI ;
_updater.configurationFile = new File("app:/configuration.xml"); //設定讀取的configuration.xml 的位置

ps:configuration.xml 內容xmlns="http://ns.adobe.com/air/framework/update/configuration/1.0別亂改
要不然一定會跳出error事件

本地的設計上都沒有錯誤的話
_updater.checkNow(); //會自動去檢查是否要使用update 視窗勒 ~


程式一執行的時候


準備可以install


===================================

2011年9月30日 星期五

PureMVC 解析

簡單概略的介紹一下 PureMVC

M = Model
V = View
C = Controller

這個framework 用了五個Design pattern (facade , command , proxy , singleton , observer
當初為什麼要用這個framework的原因 ?
1.架構吸引人
2.分工方便

不想用的原因是
1.code 會寫的很冗長
2.並不是每個人都可以理解這錮中含意
3.Unit test 不方便

1.Mediator 跟 ViewComponent(VC)
在使用上
Mediator 就是在控制view的一個view controller
但Mediator 是可以監聽command和發送command的喔
可以從Mediator裡面看到他提供這兩個關鍵方法: listNotificationInterests() 和handleNotification()

實作上

在new的時候 就是要做到提供一個字串名稱和VC 做這個mediator 的註冊
以便facade可以看到這個mediator並對她做取用和塞值


//============再補充 ===================



2011年9月29日 星期四

SharedEvents 使用方式

在ApplicationDomain異域裡面
base.swf 載入子child.swf
兩者要達到溝通的方式 :
(1). LocalConnection
(2). SharedEvent
============================================================================
第一種方式
因為上一次專案 有過慘痛的例子
就是在傳送大量訊息的時候 會有可以中斷connecting 必須要做reconnecting
所以就不考慮這個方式了
第二種方式
來自於一個大師推薦的 不過也算經過一個穩定的測試 (至少比LocadConnection來的穩定多了

============================================================================
在 AS3 LoaderInfo.sharedEvents 可以在不開放 Cross-Domain Scripting 限制下
互相發送事件,算是解決我們的一些複雜的問題了.

step 1.
我們一定會做載入swf 的
var  loader :Loader = new  Loader () ;
var  context : LoaderContext = new  LoaderContext () ;
/* 加載到新域(獨立運行)*/
context . applicationDomain = new  ApplicationDomain () ;
loader . load ( new  URLRequest ( " Child.swf " ) , context ) ;              loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);


(待續 ) 乾 寫個sample code 怎麼那麼困難阿