AMFPHP flash in AS2

前面兩篇介紹了amfphp介面與php端
最後來介紹最重要的flash端(畢竟最主要是flash要連資料庫嘛...)
因為AS3到現在熟悉程度還是有限`
AS2...也只是略知一二....|||

切入正題
AS2裡面若要作Remote需要先import "RemotingClasses"元件至元件庫

*update 20110928
發現"RemotingClasses在"flash cs4"已經消失,不過已經找到原來的Class檔案,使用方式為檔案解壓縮後將資料夾檔案與publish的sef檔放在同一層目錄即可。
RemotingClasses 立即下載

接著是code部份就由以下範例解說

php端

<?php
class test{
var $dbhost = "localhost";
var $dbname = "test";
var $dbuser = "root";
var $dbpass = "12345678";
var $conn;

function getData(){
$this->conn = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
mysql_select_db ($this->dbname, $this->conn);
$rs=mysql_query("SELECT * FROM myTest", $this->conn);
return $rs;
}

}
?>


先看看service端是否有抓到資料


確定有抓到資料後
接著是flash端

import mx.remoting.*;
import mx.rpc.*;

//gateway位置 也就是在amfphp資料夾下的gateway.php
var gatewayUrl:String = "http://localhost/amfphp/gateway.php"

//新增一個service
//var 新增service:Service = new Service(gatewayUrl, null, 'amfphp內service名稱');
var myService:Service = new Service(gatewayUrl, null, 'test');

//var 自訂:PendingCall = 新增service.amfphp內function名稱;
var myTest:PendingCall = myService.getData();

//自訂.responder = new RelayResponder(this, "成功後執行function", "成功後執行function");
myTest.responder = new RelayResponder(this, "handleGet", null);

//成功後執行function
/*
function handleGet(自定:ResultEvent){
var 同amfphp內function名稱:RecordSet = RecordSet(自定.result);
變數 = 同amfphp內function名稱.getItemAt(第幾比資料).資料庫欄;
^^^^^^^^^
從0開始算
}
*/
function handleGet(r:ResultEvent){
var getData:RecordSet = RecordSet(r.result);
myVar = getData.getItemAt(0).number;
trace("myVar = "+myVar);
}



在trace後確認有抓到變數


這樣就完成最基礎的Remoting

Half man, half building: The Corpus science museum


27 March, 2008
By Audrey Ward

Visitors take a journey through the human body in new Dutch museum

The Corpus is a new museum on the outskirts of the Hague in the Netherlands that is both a science education centre and an amusement park.

The building, designed by Dutch architect Reco Productions International BV, incorporates a 35m-high seated human figure created by artist De Ridder.

The museum offers visitors as young as eight the opportunity to go on a journey through the human body, where they can see, feel and hear how the body works.

Henri Remmers, managing director of Reco Productions International BV, said: “Our vision is that visitors to Corpus ‘journey through the human body’ will have a different view on their body when they return home.”

All the walls and halls are modelled with fibreglass to resemble the inside of a giant human body.

The museum has a number of permanent and variable exhibitions. It uses the latest technology in the field of imagery, sound and 3D effects to present and explain the medical aspects of the human body.

The architect worked with designer Andre Postma and constructor IMD. Heddes Bouw was contractor on the scheme.

The museum opened to the public last week.





















真的太帥氣了!
有機會真想去逛逛這博物館

原文連結:http://www.building.co.uk/story.asp?storycode=3109824

[轉]朱木炎拿不到金牌的原因?

都軟掉了...


這...難道就是真相嗎XD

轉自:http://share.youthwant.com.tw/sh.php?do=D&id=13051314

AMFPHP php端

首先開啟任意一個文字編輯器並輸入以下程式碼


< ?php
class HelloWorld
{
//我是註解
function say($sMessage)
{
return '結果是.... ' . $sMessage;
}
}
?>

其實很不想用hello world當範例...
下圖為amfphp與php function間的對應

class HelloWorld 橘色線段

function say 紅色線段

($sMessage) 紫色線段

return '結果是.... ' . $sMessage; 藍色線段


有需要注意部份有幾點 1. class "HelloWorld" =>這一定要與檔案名稱相同 ex: helloworld.php 2. function 後接著就是function的名稱,可依照個人習慣而定
3. 如範例:function say ($sMessage) 後面括號中即為變數不限定數量,只要使用" , "來區隔即可
ex: $a, $b, ......
4. 若沒有要使用變數(只需取得值)括號內就不需要填任何東西
5. return 後面即為最後所需的值

以上為只使用php內語法
但若需要連結資料庫呢?
下面這範例提供參考


< ?php
class test{
var $dbhost = "localhost";     //資料庫位置 
var $dbname = "myTest";      //資料庫名稱 
var $dbuser = "test";           //使用者名稱
var $dbpass = "12345678";   //使用者密碼 
var $conn;

function getData(){
$this->conn = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
mysql_select_db ($this->dbname, $this->conn);
$rs=mysql_query("SELECT 欄 FROM 表單 WHERE 位)", $this->conn);
return $rs; 
} 
}

?>
這樣即可獲得到資料庫的資料
如下範例


MySQL的語法在此就不多作說明
若有興趣google一下即可獲得
看似很難的東西其實也能很簡單

AMFPHP 1.9b 基本介紹

最近打混有點大...有點良心不安...

進入正文
Flash若想要與資料庫連結有不少方式
現在就先介紹這一種透過php與MySQL連結

AMFPHP官方網頁

其實網路上有不少這方面相關資源
中文、英文、法文、西班牙文都有不少相關資料
但說實在話...當我剛接觸時還真是搞得一團亂
現在稍微有點心得來分享一下

以下當作對於架設環境有基本了解(apache、MySQL...)
首先去官方網站下載主程式
因為版本很多...不過還是推薦目前最新的1.9b(介面實在好太多..功能也強大)
下圖為下載完解壓縮後



接著就直接使用瀏覽器來觀看(如下圖)
輸入http://localhost/amfphp/ or http://127.0.0.1/amfphp/


點選Browser後及進入介面
下圖為首次進入出現的選項


Gateway location 為amfphp內的gateway的位置(預設位置一般來說可以不用變)
Encoding 預設部份也不用去動(兩個好像為新舊版差異)
Set table after call 這部份也無須去更動,只是差別在call function時先呈現哪一個

進入後基本介面(下圖)


按下call後所呈現如下











假若過程中有需要輸入變數也可以直接在這測試


接下來兩篇將介紹裡面service寫法及flash端如何來取得以及寫入資料