Flash

flash AS3.0 amfphp

OJR 2009. 8. 5. 16:02

http://hi.baidu.com/wwwanq/blog/item/60a32a4e6551183eaec3ab17.html


// Wade Arnold: 1/6/2008
// Example is designed to show how to use PHP sessions.
package {
    // required for flash file and output display
    import flash.display.MovieClip;
    import fl.events.*;
    import flash.events.*;
    // required to send/recieve data over AMF
    import flash.net.NetConnection;
    import flash.net.Responder;
 
    // Flash CS3 Document Class.
    public class Counter extends MovieClip {
        private var gateway:String = "http://localhost/server/amfphp/gateway.php";
        private var connection:NetConnection;
        private var responder:Responder;
 
        public function Counter() {
            trace("AMFPHP Session Counter Example");
            // Event listner for buttons
            increment_btn.addEventListener(MouseEvent.CLICK, incrementCounter);
            reset_btn.addEventListener(MouseEvent.CLICK, resetCounter);
            destroy_btn.addEventListener(MouseEvent.CLICK, destroySession);
            // Responder to handle data returned from AMFPHP.
            responder = new Responder(onResult, onFault);
            connection = new NetConnection;
            // Gateway.php url for NetConnection
            connection.connect(gateway);
        }
 
        // Method run when the "Increment Counter" button is clicked.
        public function incrementCounter(e:MouseEvent):void {
            // Send the data to the remote server.
            connection.call("Counter.increment", responder);
        }
        // Method run when the "Rest Counter" button is clicked.
        public function resetCounter(e:MouseEvent):void {
            // Send the data to the remote server.
            connection.call("Counter.unregister", responder);
        }
 
        // Method run when the "Destroy Session" button is clicked.
        public function destroySession(e:MouseEvent):void {
            // Send the data to the remote server.
            connection.call("Counter.destroy", responder);
        }
 
        // Handle a successful AMF call. This method is defined by the responder.
        private function onResult(result:Object):void {
            response_txt.text = String(result);
        }
 
        // Handle an unsuccessfull AMF call. This is method is dedined by the responder.
        private function onFault(fault:Object):void {
            response_txt.text = String(fault.description);
        }
    }
}

php:

< ?php
// Wade Arnold: 1/6/2008
// Example is designed to show how to use PHP sessions.
class Counter {
 
    public function __construct() {
        // Check if the session is available or create it.
        if (!isset($_SESSION['count'])) {   
            $_SESSION['count'] = 0;
        }
    }
    // Used to increment the session variable count.
    public function increment() {
        $_SESSION['count']++;
    return $_SESSION['count'];
    }
    // used to destroy the session variable and start over.
    public function unregister() {
        unset($_SESSION['count']);
    return true;
    }
    // remove the entire session from the server.
    public function destroy() {
        session_destroy();
    return true;
    }
}



//


참고