Hey,

I am using Flex2-AMFPHP in a project and it works great!

There has been some discussion in this list about what to change by subclassing NetConnection.

Well hey, here is my stuff;

package com.teotigraphix.amf
{
        import flash.net.NetConnection;
       
        public class NetConnection2 extends NetConnection
        {
                public function AppendToGatewayUrl(append:String):void
                {
                }
              
                public function AddHeader():void
                {
                }
               
                public function ReplaceGatewayUrl():void
                {
                }
        }
}

Service abstract class

package com.teotigraphix.amf
{
    import flash.util.trace;
   
    import flash.net.Responder;
    import flash.net.NetConnection;
    import flash.net.ObjectEncoding;
   
    import flash.events.Event;
    import flash.events.EventDispatcher;
   
    import mx.utils.ObjectUtil;
   
    import com.teotigraphix.amf.NetConnection2;
   
    import com.teotigraphix.events.FaultEvent;
    import com.teotigraphix.events.ResultEvent;
   
    /**
     * The abstract class to create a concrete service implementation using AMFPHP.
     * @author Michael J. Schmalle
     * @date 03-06-06
     */
    public class AMFService extends EventDispatcher
    {
        protected var _gateway:NetConnection2;
        private var __gatewayURL:String = "http://localhost/teotigraphix/flashservices/gateway.php";
        protected var classPath:String = "";
       
        /**
         * The url leading to the service's gateway.php file.
         * @usage myService.gatewayURL = "http://www.example.com/flashservices/gateway.php";
         */
        public function set gatewayURL(value:String):void
        {
            __gatewayURL = value;
        }
        public function get gatewayURL():String
        {
            return __gatewayURL;
        }
       
        /**
         * Create the gateway connection, set ObjectEncoding to AMF0 and connect the gateway to the gateway url.
         * @see com.teotigraphix.amf.NetConnection2
         */
        public function AMFService()
        {
            super();
            _gateway = new NetConnection2();
            _gateway.objectEncoding = ObjectEncoding.AMF0;
            _gateway.connect(__gatewayURL);
        }   
       
        /**
         * NOTE :: This works but it needs to have the arguments dealt with, so I didn't implement it yet.
         * Can anyone tell me what I am doing wrong to get the arguments passed to php correctly ?
         * Wrapper for the fudged service call.
         * @param methodName a string indicating the method to invoke within this service.
         * @param responder a Responder instance that will activate the default onResult() or onFault() handlers.
         */
        protected function service(methodName:String, responder:Responder, ... args):void
        {
            //trace("service() " + classPath + "." + methodName);
            _gateway.call(classPath + "." + methodName, responder, args);
        }
       
        // ========================================================================
        // Public _gateway event handlers
        // ========================================================================
   
        /**
         * Default result handler for the Responder.
         * @param event an Event that holds {event.result}.
         */
        public function onResult(event:Object):void
        {
            dispatchEvent(new ResultEvent("result", event));
        }

        /**
         * Default fault handler for the Responder.
         * @param event an Event that holds {event.fault}.
         */
        public function onFault(event:Object):void
        {
            //trace("onFault()", ObjectUtil.toString(event));
            dispatchEvent(new FaultEvent("fault", event));
        }
    }
}

Subclassed service...



package com.teotigraphix.amf.files
{
    import com.teotigraphix.amf.AMFService;
   
    import com.teotigraphix.events.ResultEvent;
    import flash.net.Responder;
    import flash.util.trace;
    import com.teotigraphix.amf.files.IFileService;

    public class AMFFileService extends AMFService implements IFileService
    {
         
        public function AMFFileService()
        {
            super();
            classPath = "com.teotigraphix.amf.files.AMFFileService";
        }
       
        /**
         *
         */
        public function getAllDirectories(directory:String):void
        {
            var responder:Responder = new Responder(onAllDirectories, onFault);
            //service("getAllDirectories", responder, directory);
            _gateway.call(classPath + "." + "getAllDirectories", responder, directory);
        }
       
        private function onAllDirectories(e:*):void
        {
            //trace("onAllDirectories()");
            var ev:ResultEvent = new ResultEvent("allDirectoriesLoaded", e);
            dispatchEvent(ev);
        }

        /**
         *
         */
        public function getFile(url:String):void
        {
            var responder:Responder = new Responder(onGetFile, onFault);
           
            // THIS IS WHAT IS MESSING UP HELP!!!
            //service("getFile", responder, file);
       
            _gateway.call(classPath + "." + "getFile", responder, url);
        }

        /**
         *
         */
        private function onGetFile(resultData:*):void
        {
            resultData = resultData.split("\r").join("");
            dispatchEvent(new ResultEvent(ResultEvent.LOADED, resultData));           
        }
    }
}

Anyway, this was written ON THE FLY, not rfactoring yet. It works great!

Peace, Mike

On 3/20/06, mvbaffa <[EMAIL PROTECTED]> wrote:
Hi all,

I have a new project and I would like to do it in Flex 2.0 The problem
is that I don't know which server technology to use.

Have you already tested any of these technologies. Which one is
working ok for the Beta 1 of Flex 2.0.

Wiil I need to use FES ????

Thanks in advance









--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS






--
What goes up, does come down.

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to