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

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