Testing your AMFPHP installation

Posted by PunNeng, Sun Nov 27 01:52:00 UTC 2005

ตรวจสอบ gateway.php ก่อนเลยครับ ว่าใช้ได้หรือเป่า จากนั้นมาลองกันเลย เริ่มด้วย save code ข้างล่างเป็น HelloWorld.php ไว้ใน services folder

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
<?php
class HelloWorld{
    function HelloWorld(){
        $this->methodTable = array(
            "say" => array(
                "access" => "remote",
                "description" => "Pings back a message"
            )
        );
    }

    function say($sMessage){
        return 'You said: ' . $sMessage;
    }
}
?>

เสร็จแล้ว มาที่ Flash ไปเอาตัว RemotingClasses กับ RemotingDebugClasses มาแปะไว้ก่อน ที่ Window > Common Libraries > Remoting แล้วยัด code นี้ไปที่งาน Flash ของเราเลย

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
import mx.remoting.*;
import mx.rpc.*;
import mx.remoting.debug.NetDebug;

var gatewayUrl:String="http://localhost/flashservices/gateway.php";

NetDebug.initialize();
var _service:Service = new Service(gatewayUrl, null, 'HelloWorld', null , null);
var pc:PendingCall = _service.say("Hello world!");
pc.responder = new RelayResponder(this, "handleResult", "handleError");

function handleResult(re:ResultEvent){
    trace('The result is: ' + re.result);
}

function handleError(fe:FaultEvent){
    trace('There has been an error');
    trace('result : '+ fe.fault.faultstring);
}

แค่นี้ก้อเป็นอันเสร็จเรียบร้อย ลองสั่ง publish เลย แล้วมาดูผลกัน ควรจะได้ตามนี้นะ

The result is: You said: Hello world!

แล้วในหน้า NetConnection Debugger จะเป็นแบบนี้

ถ้าไม่ได้ น่าจะมีสองสาเหตุ อันแรกคือตอน Compilation errors

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 8: The class 'Service' could not be loaded.
     var _service:Service = new Service(gatewayUrl, null, 'HelloWorld', null , null);

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 9: The class 'PendingCall' could not be loaded.
     var pc:PendingCall = _service.say("Hello world!");

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 12: The class 'ResultEvent' could not be loaded.
     function handleResult(re:ResultEvent)

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 17: The class 'FaultEvent' could not be loaded.
     function handleError(fe:FaultEvent)

Total ActionScript Errors: 4     Reported Errors: 4

อันนี้คือไม่ได้โยนเจ้าตัว Remoting Component ทั้งสองตัว ลงไปแปะเอาไว้ หรืออย่างที่สอง Runtime errors

Error opening URL http://localhost/flashservices/gateway.php

อันนี้อาจจะเป็นไปได้ทั้งยังไม่ได้เซ็ต gatewayUrl หรือ ยังไม่ได้เปิด server ของเรา แต่ถ้าได้อันนี้

There has been an error

หา errors ได้จาก NetConnection Debugger

Status (object #2)
.....description: "The class {HelloWorld} could not be constructed, check the stack trace for the root cause"
.....details: "c:\pat\projets\amfphp\src\actions\ClassLoaderAction.php"
.....level: "User Error"
.....line: 61
.....exceptionStack (object #3)
..........[0] (object #4)
...............[0] (object #5)
....................code: 256
....................description: "The class {HelloWorld} could not be constructed, check the stack trace for the root cause"
....................details: "c:\pat\projets\amfphp\src\actions\ClassLoaderAction.php"
....................level: "User Error"
....................line: 61
..........[1] (object #6)
...............[0] (object #7)
....................code: 256
....................description: "The class {HelloWorld} could not be loaded.  The class file exists but may contain syntax errors, or the class is misnamed."
....................details: "c:\pat\projets\amfphp\src\actions\ClassLoaderAction.php"
....................level: "User Error"
....................line: 83

หมายความว่า AMFPHP หา class ของเราไม่เจอ อาจจะเพราะว่ายังไม่ได้สร้าง class ไว้ใน services folder หรือยังไม่ได้ไปเซ็ต base class path ใน gateway.php

เรียบร้อยยยแว้วววว

แก้ไขล่าสุด วันที่ 17 มิถุนายน 2550 เวลา 2.50 น.

ข้อมูลจาก
http://www.amfphp.org/docs/testingamfphp.html

Filed Under: General | Tags: amfphp flash flash remoting howto php

Comments

  1. Thanyarat 09.11.08 / 13PM

    ลองศึกษาแล้ว น่าสนใจมากเลยค่ะ ถ้าต้องการจะศึกษาเพิ่มเติมจะหาได้จากเว็บไซต์ไหนค่ะ รึว่ามีหนังสือดีๆ จะแนะนำไหมค่ะ ขอบคุณล่วงหน้าค่ะ

Have your say

A name is required. You may use HTML in your comments.




codegent: we're hiring