Реших, че ми е крайно време да пробвам новата бета и да видя какви са промените.
Мога да кажа, че останах очарован
Не гледах новите промени по компонентите, mxml-а etc, ами реших направо да пробвам дълбоките води – data centric development ( това значи 1во да си напишеш бекенда и да вържеш флекса към service-ите )
Понеже не знаех кода за цялата далавера, реших да ползвам wizard-a.
Това е класът, който ползвах.
<?php class TestService { public function hello() { return "hello"; } public function helloWithName($name) { return "Hello " . $name; } } ?>
Първо при създаване на нов проект – посочих PHP, посочих си web root и root url-a ( htdocs, localhost ), след което посочих къде се намира PHP класът, изтегли ми автоматично Zend Framework, и създаде 2 класа за ползване.
Важният е това :
/** * This is a generated class and is not intended for modfication. To customize behavior * of this service wrapper you may modify the generated sub-class of this class - TestService.as. */ package services.testservice { import mx.rpc.AsyncToken; import com.adobe.fiber.core.model_internal; import mx.rpc.AbstractOperation; import mx.collections.ItemResponder; import mx.rpc.remoting.RemoteObject; import mx.rpc.remoting.Operation; import com.adobe.fiber.services.wrapper.RemoteObjectServiceWrapper; import com.adobe.fiber.valueobjects.AvailablePropertyIterator; import com.adobe.serializers.utility.TypeUtility; [ExcludeClass] internal class _Super_TestService extends RemoteObjectServiceWrapper { // Constructor public function _Super_TestService() { // initialize service control _serviceControl = new RemoteObject(); var operations:Object = new Object(); var operation:Operation; operation = new Operation(null, "hello"); operation.resultType = String; operations["hello"] = operation; operation = new Operation(null, "helloWithName"); operation.resultType = Object; operations["helloWithName"] = operation; _serviceControl.operations = operations; _serviceControl.convertResultHandler = TypeUtility.convertResultHandler; _serviceControl.source = "TestService"; _serviceControl.endpoint = "gateway.php"; _serviceControl.destination = "TestService"; model_internal::initialize(); } /** * This method is a generated wrapper used to call the 'hello' operation. It returns an AsyncToken whose * result property will be populated with the result of the operation when the server response is received. * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value. * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events. * * @see mx.rpc.AsyncToken * @see mx.rpc.CallResponder * * @return an AsyncToken whose result property will be populated with the result of the operation when the server response is received. */ public function hello() : AsyncToken { var _internal_operation:AbstractOperation = _serviceControl.getOperation("hello"); var _internal_token:AsyncToken = _internal_operation.send() ; return _internal_token; } /** * This method is a generated wrapper used to call the 'helloWithName' operation. It returns an AsyncToken whose * result property will be populated with the result of the operation when the server response is received. * To use this result from MXML code, define a CallResponder component and assign its token property to this method's return value. * You can then bind to CallResponder.lastResult or listen for the CallResponder.result or fault events. * * @see mx.rpc.AsyncToken * @see mx.rpc.CallResponder * * @return an AsyncToken whose result property will be populated with the result of the operation when the server response is received. */ public function helloWithName(name:Object) : AsyncToken { var _internal_operation:AbstractOperation = _serviceControl.getOperation("helloWithName"); var _internal_token:AsyncToken = _internal_operation.send(name) ; return _internal_token; } } }
А другият е просто наследен с по-хубаво име и за надграждане.
/** * This is a generated sub-class of _TestService.as and is intended for behavior * customization. This class is only generated when there is no file already present * at its target location. Thus custom behavior that you add here will survive regeneration * of the super-class. **/ package services.testservice { public class TestService extends _Super_TestService { } }
А самото ползване става така :
<?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/halo" minWidth="1024" minHeight="768" xmlns:testservice="services.testservice.*"> <s:layout> <s:VerticalLayout/> </s:layout> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.FlexEvent; import mx.rpc.events.ResultEvent; protected function button1_clickHandler(event:MouseEvent):void { //da izvikame service-a var s:String = nameInput.text; helloResult.token = testService.helloWithName(s); helloResult.addEventListener(ResultEvent.RESULT, onResult); } protected function onResult(e:ResultEvent):void { Alert.show(e.result.toString()); } ]]> </fx:Script> <fx:Declarations> <s:CallResponder id="helloResult"/> <testservice:TestService id="testService" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/> </fx:Declarations> <s:Button click="button1_clickHandler(event)" /> <s:TextInput id="nameInput" /> </s:Application>
Направо да не повярваш колко лесно става цялата тази работа !
Евала на Adobe.
Мисля в скоро време да направя 1 видео по-подробно за тези сървизи и как да се качи такова чудо на production сървър.
