AMFPHP配置详细教程

AMFPHP配置详细教程 不想传递拆分字符串,解析串行XML了吧? 厌烦JSON了? 试试AMF吧,传送多种数据格式。 首先下载 AMFPHP(本教程使用1.9BETA2)你可以选择其他版本   在这里选择下载 下载后,解压缩,把文件夹中的amfphp文件夹拷贝到 APACHE服务器的网站根目录。 然后打开浏览器,输入 http://localhost/amfphp/gateway.php     确定 如果提示: amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash. Note: If you're reading an old tutorial, it will tell you that you should see a download window instead of this message. This confused people so this is the new behaviour starting from amfphp 1.2. View the amfphp documentation Load the service browser 说明安装成功。 打开网站根目录的 AMFPHP 文件夹,进入 SERVICES 文件夹,新建一个 PHP 文件命名为 HELLOWORLD.php 拷贝以下代码: <?php class HelloWorld { function HelloWorld() { $this->methodTable = array ( "say" => array ( "access" => "remote", "description" => "Pings back a message" ) ); } function say($sMessage) { return 'You said: ' . $sMessage; } } ?> 保存! 在浏览器地址栏输入 http://localhost/amfphp/browser/ 回车 AMFPHP 的项目管理器: 单击  HelloWorld 看到一下内容,就是 HELLOWORLD 项目具体内容:sMessage 输入内容 ( 比如 "xiaoxiaocainiao")    单击 call 按钮: 看到页面下方的提示结果: 好了,你已经初步学会安装 AMFPHP 并使用了,具体的语法,函数,还需要查看一下官方的文档啦。 下面一起来做一个 FLASH 通过 AMFPHP PHP 交互的小例子: 到这里下载 AMFPHP for FLASH8的组件,如果你使用其他版本,请到这里选择下载: http://www.adobe.com/products/flashremoting/downloads/components/ 下载后安装,完毕后打开 FLASH  ,查看  窗口 | 公用库 |Remoting” 就可以看到 AMFPHP 的组件了。 新建立一个工程,拖一个 RemotingClasses 组件到舞台的任何地方,再拖一个 List 组件,命名为 myls, 拖一个 Button 组件,命名为 "mybt" 在第一帧的代码行复制以下代码: import mx.remoting.*; import mx.rpc.*; import mx.utils.Delegate; import mx.remoting.debug.NetDebug; var gatewayUrl:String = "http://localhost/amfphp/gateway.php"; var service:Service; NetDebug.initialize(); service = new Service(gatewayUrl, null, "PersonService"); function getPerson() { trace("getPerson"); var pc:PendingCall = service.getPerson(); pc.responder = new RelayResponder(this, "handleGetPerson"); } function handleGetPerson(re:ResultEvent) { trace("handleGetPerson"); trace(re.result.getItemAt(0).name); _root.mytree.dataProvider = re.result; _root.mydg.dataProvider = re.result; } function onClick() { getPerson(); } mybt.addEventListener("click", Delegate.create(this, onClick)); 在 AMFPHP SERVICES 文件夹下新建一个文件,命名为 PersonService.php 复制一下内容到 PersonService.php <?php class PersonService { function PersonService() { $this->methodTable=array( "getPerson"=> array( "access"=>"remote" ) ); mysql_connect('localhost','root','wuliqunao'); mysql_select_db('test'); } function getPerson() { $sql=sprintf("SELECT * FROM persons"); $query=mysql_query($sql); return $query; } } ?> 好了,发布你的程序,单击 Button 按钮,看到结果: 当然了,你的本机需要有个 MYSQL 数据有,里面简历一个 test 数据库,这个库里面创建一个 persons 数据表,表里 2 个字段,一个是 name ,一个是 age. (表告诉我,你搞不好这个库啊,搜一个 MYSQL 数据库入门教程,一下就知道啦。) 好了,大功告成,开始学习 AMFPHP 之路吧 ~~~~ AMFPhp  与  Flex Builder3  的交互(一) 写一下php与Flex的交互。作为学习笔记,现在这方面中文文档貌似比较少。下面的大多数都来自 http://www.sephiroth.it 。英文好的同学可以直接去看。 好,先说一下我的基本配置吧。php 版本:php-5.2.6-Win32.zip,apache版本:apache_2.2.8-win32-x86,mysql版本:mysql-5.0.51a-win32.具体的配置方法就不说了,去网上搜吧,太多了。我的本地服务放在 D:\php。 好,ok。 在 http://sourceforge.net/project/showfiles.php?group_id=72483#files下载amfphp压缩包,我的版本是 amfphp-1.9.beta.20070513.zip 。下载后,解压到我的本地服务目录,即 D:\php 。然后再浏览器中输入:http://localhost/amfphp/gateway.php 如果你看到了如下信息,就说明安装成功了。 amfphp and this gateway are installed correctly. You may now connect to this gateway from Flash. AMF C Extension is loaded and enabled. Note: If you're reading an old tutorial, it will tell you that you should see a download window instead of this message. This confused people so this is the new behaviour starting from amfphp 1.2. View the amfphp documentation Load the service browser 好了,让我们写一个HelloWorld程序吧。首先打开D:\php\amfphp\services目录,新建一个HelloWorld.php文件,在文件中输入以下代码: 1. <?php 2. class HelloWorld 3. { 4. 5. function sayHello() 6. { 7. return "Hello World!"; 8. } 9.   } 10. ?> 复制代码 好啦,php端,就先这样了。然后我们写flex端的吧。在Flex builder3新建一个Flex工程。 需要注意的是,在Application server type选择php。呵呵,下一步。 在web root 下填入 D:\php 即我的本地web服务的目录。root url 填入: http://127.0.0.1 即本地IP啦,呵呵。然后下一步,如果你不改源文件的目录的话,就直接Finish啦。 好,在src里再新建一个xml文档,名字叫: services-config.xml ,打开,输入以下代码,这个flex与amfphp的配置文件。 1. <?xml version="1.0" encoding="UTF-8"?> 2. <services-config> 3. <services> 4. <service id="amfphp-flashremoting-service" class="flex.messaging.services.RemotingService" messageTypes="flex.messaging.messages.RemotingMessage"> 5. <destination id="amfphp"> 6. <channels> 7. <channel ref="my-amfphp"/> 8. </channels> 9. <properties> 10. <source>*</source> 11. </properties> 12. </destination> 13. </service> 14. </services> 15. <channels> 16. <channel-definition id="my-amfphp" class="mx.messaging.channels.AMFChannel"> 17. <endpoint uri="http://127.0.0.1/amfphp/gateway.php" class="flex.messaging.endpoints.AMFEndpoint"/> 18. </channel-definition> 19. </channels> 20. </services-config> 复制代码 然后右键点击你的项目,选择Properties选项,在弹出的对话框里选择Flex Compiler,在Additional compiler arguments里加入 -services "services-config.xml",如图: 点击src ,打开AMFphp.mxml,好输入以下代码: 1. <?xml version="1.0" encoding="utf-8"?> 2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" viewSourceURL="srcview/index.html"> 3.     <mx:RemoteObject id="myservice" fault="faultHandler(event)" showBusyCursor="true" source="HelloWorld" destination="amfphp"> 4.         <mx:method name="sayHello" result="resultHandler(event)" /> 5.     </mx:RemoteObject> 6. 7.     <mx:Script> 8.         <![CDATA[ 9.             import mx.managers.CursorManager; 10.             import mx.rpc.events.ResultEvent; 11.             import mx.rpc.events.FaultEvent; 12.             private function faultHandler(fault:FaultEvent):void 13.             { 14.                 CursorManager.removeBusyCursor(); 15.                 result_text.text = "code:\n" + fault.fault.faultCode + "\n\nMessage:\n" + fault.fault.faultString + "\n\nDetail:\n" + fault.fault.faultDetail; 16.             } 17. 18.             private function resultHandler(evt:ResultEvent):void 19.             { 20.                 result_text.text = evt.message.body.toString(); // same as: evt.result.toString(); 21.             } 22.         ]]> 23.     </mx:Script> 24. 25.     <mx:Button x="250" y="157" label="sayHello" width="79" click="myservice.getOperation('sayHello').send();"/> 26.     <mx:Button x="250" y="187" label="test fault" click="myservice.getOperation('foo').send(); "/> 27.     <mx:TextArea x="10" y="36" width="319" height="113" id="result_text"/> 28.     <mx:Label x="10" y="10" text="Result:"/> 29. </mx:Application> 复制代码 好,先不管代码的含义,我们运行一下吧,如果你看见了下面的图片,你就成功了。 点击sayHello按钮,看见它和你问好了吗? 看见了!oh,Good.你太有天赋了,不编程可惜了,呵呵。今天先到这,有空继续。 (本文与作者博客同步更新,呵呵,做个广告,博客地址在下面) 好,让我们来分析一下这段代码吧! 在 <mx:RemoteObject> 下呢,定义的就是 RemoteObject 相关的一些东东 . (这话题听着别扭), id 这个就不解释了, fault 就是当服务调用失败并且操作自身不处理时,调度 fault 事件。 showBusyCursor 呢,如果为  true ,在执行服务时就会显示忙碌光标。在这里重点是后两个属性, source destination source 后面写的是,你在服务器上的文件名,也就是咱们用 php 写的那个类的文件的名字,即在 D:\php\amfphp\services 目录下,这个算是咱们本地服务的根目录。如果你要建一个新的目录为 hello ,然后把 HelloWorld.php 这个文件放进去,那么我们的程序应该改一下,即 source = "hello.HelloWorld"  destination 有代表什么呢 ? 服务的目标。这个值应该与 services-config.xml 文件中的目标条目匹配,那好,去找一下 services-config.xml 这个文件吧,看看有这个叫做 destination 这个东东吗? 该  <mx:method /> 这行了,很简单,这个就是咱们要用的方法啊,名字和 php 里面方法的名字要一致哦。 另外,需要注意的是在我们的显示界面的代码中,在 label sayHello <mx:Button /> 里面, click = "myservice.getOperation('sayHello').send"  ,这行代码的意思就是当我们点击按钮的时候,将要执行我们的 remoteObject 对像中的 sayHello 方法,并且等待 result 事件,如果一切顺利, php 端会给我们返回一个叫做 "Hello world" 的字符串,然后,将去调用 <![CDATA  .....  ]]> 里面的 ResultHandler 函数,接着我们的 result_text 文本就有任务啦,那就是显示这个字符串。怎么样,很简单吧。(其他的请看源代码注释,我也是刚研究,有错误的地方请指正) 哇,今天学到了不少东西,明天继续。原来世界这么美好!  1. <?xml version="1.0" encoding="utf-8"?> 2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" viewSourceURL="srcview/index.html"> 3.     <mx:RemoteObject id="myservice" fault="FaultHandler(event)" showBusyCursor="true" source="hello.HelloWorld" destination="amfphp"> 4.         <mx:method name="sayHello" result="ResultHandler(event)" /> 5.     </mx:RemoteObject> 6. 7.     <mx:Script> 8.         <![CDATA[ 9.             import mx.managers.CursorManager; 10.             import mx.rpc.events.ResultEvent; 11.             import mx.rpc.events.FaultEvent; 12.             // 注:错误处理函数 13.             private function FaultHandler(fault:FaultEvent):void 14.             { 15.                                 // 注:删除忙状态光标                16.                 CursorManager.removeBusyCursor(); 17.                 // 注:返回的错误信息,让其在 result_test 中显示出来 18.                 result_text.text = "code:\n" + fault.fault.faultCode + "\n\nMessage:\n" + fault.fault.faultString + "\n\nDetail:\n" + fault.fault.faultDetail; 19.             } 20. 21.             private function ResultHandler(evt:ResultEvent):void 22.             { 23.                 // 注: 将获得的结果转化为 String 类型,并交给 result_text 显示出来 24.                 result_text.text = evt.message.body.toString(); // same as: evt.result.toString(); 25.             } 26.         ]]> 27.     </mx:Script> 28.         <!-- 下面这个东东呢,就是我们的显示界面了, 2 个按钮、一个文本区域、一个标签。  --> 29.     <mx:Button x="250" y="157" label="sayHello" width="79" click="myservice.getOperation('sayHello').send();"/> 30.     <mx:Button x="250" y="187" label="test fault" click="myservice.getOperation('hoo').send(); "/> 31.     <mx:TextArea x="10" y="36" width="319" height="113" id="result_text"/> 32.     <mx:Label x="10" y="10" text="Result:"/> 33. </mx:Application> 复制代码 Amfphp Flex 交互 -- (三 ) 向 php 端写数据,并读返回数据 好,还记得我们第一章讲得吗?不记得啦?看下这个链接啊  http://bbs.actionscript3.cn/thread-16541-1-1.html 我们今天做的呢,前端,只要在第一章代码的基础上修改一下就好了,主要的是php端的改变。 所以呢,你可以在你以前的工程里面新建一个 Application ,然后粘贴下面的代码哦。 先看一下flex端的代码: 1. <?xml version="1.0" encoding="utf-8"?> 2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" viewSourceURL="srcview/index.html"> 3.     <mx:RemoteObject id="myservice" fault="FaultHandler(event)" showBusyCursor="true" source="hello.AddEmailDb" destination="amfphp"> 4.         <mx:method name="InputUser" result="ResultHandler(event)" /> 5.     </mx:RemoteObject> 6. 7.     <mx:Script> 8.         <![CDATA[ 9.             import mx.managers.CursorManager; 10.             import mx.rpc.events.ResultEvent; 11.             import mx.rpc.events.FaultEvent; 12.             // 注:错误处理函数 13.             private function FaultHandler(fault:FaultEvent):void 14.             { 15.                                 // 注:删除忙状态光标                16.                 CursorManager.removeBusyCursor(); 17.                 // 注:返回的错误信息,让其在 result_test 中显示出来 18.                 result_text.text = "code:\n" + fault.fault.faultCode + "\n\nMessage:\n" + fault.fault.faultString + "\n\nDetail:\n" + fault.fault.faultDetail; 19.             } 20. 21.             private function ResultHandler(evt:ResultEvent):void 22.             { 23.                 // 注: 将获得的结果转化为 String 类型,并交给 result_text 显示出来 24.                result_text.text = evt.message.body.toString(); // same as: evt.result.toString(); 25.             } 26.         ]]> 27.     </mx:Script> 28.         <!-- 下面这些东东呢,就是我们的显示界面了, 2 个按钮、一个文本区域、一个标签。  --> 29.     <mx:Button x="250" y="157" label="Send" width="79" click="myservice.getOperation('InputUser').send(result_text.text);"/> 30.     <mx:Button x="250" y="187" label="test fault" click="myservice.getOperation('hoo').send(); "/> 31.     <mx:TextArea x="10" y="36" width="319" height="113" id="result_text"/> 32.     <mx:Label x="10" y="10" text="Result:"/> 33. 34. </mx:Application> 复制代码 发现变化了吗?没有?再仔细瞅瞅,哦!原来,在第三行, source 里面,多了一个这个东东 "hello.AddEmialDb", 这个是干什么的呢?就是帮助 flex 找到 php 文件啊。在第 4 行,即 定义 RemoteObject 的里面,我们换了一个叫做 InputUser 的函数,当然,这个一定是 php 端函数啦。在第 29 行,按钮的 click事件里面 getOperation 参数也同样改变为 InputUser ,另外 send ()函数里面好像多了一个文本信息,猜猜?恩,对,这个就是要向 Amfphp 端发送的东东。很好理解。对吧? 然后是 php 端,在D:\webroot\amfphp\services\  新建一个 hello 目录,在这个目录中再新建一个叫做 AddEmailDb.php 的文件。然后用你所熟悉的编辑器打开它,敲入以下代码:( 傻瓜,我才不敲呢,我要 copy 过去。 ”  好吧,随你!)  1. <?php 2. class AddEmailDb 3. { 4.         function InputUser($post) 5.           { 6.                 global $host,$dbTable, $dbPass,$dbId; 7.                 $host = "localhost"; 8.                 $dbId = "root"; 9.                 $dbPass = "123456"; 10.                 $dbTable = "mmmm"; 11. 12.                 $link = mysql_connect($host,$dbId,$dbPass); 13.                 mysql_select_db($dbTable); 14.                 if(!$link) 15.                 { 16.                         die('Connection Impossible:' . mysql_error()); 17.                 } 18.                 else 19.                 { 20.                         $sql = "Insert INTO mmmm(id, adressemail) VALUES ('','$post')"; 21.                         mysql_query($sql); 22. 23.                 } 24.                 mysql_close($link); 25.                 return "success"; 26. 27.         } 28. } 29. ?> 复制代码 运行你的 Apache  ,开启你的 mysql 。在 mysql 里面要建立一个数据库(我用的是 phpMyAdmin ),起个名字叫做 mmmm” ,建立一张表叫做 mmmm” 表有两个字段,一个叫做 “id” ,另一个叫做 “adressemail”。好! 在 flex 端运行。 看到与下面这张图一样的界面了吗? 看到了?继续,在文本区域内,输入一个邮件地址吧。然后点击 Send 按钮,如果文本框里出现了一个 success 的单词,那么恭喜你,成功了。你太有才了,还真不是盖的。哈哈!) php端的代码是啥意思呢?首先我们看到一个叫做 AddEmailDb的类,这里一定要注意,这个类的名字一定要和这个文件的名字相同,然后是InputUser($post)这个函数,它带了一个参数,这个参数就是我们用来接收Flex端 result_text.text 里面的信息的。然后呢,下面是一对链接mysql的语句,关键的是 1. 2. else 3. { 4.         $sql = "Insert INTO mmmm(id, adressemail) VALUES ('','$post')"; 5.         mysql_query($sql); 6. } 复制代码 这段代码,就是往数据库里面插入信息啊。 最后还注意一个         return "success";  这个就是我们发送成功后返回的那个单词啊,怎么样,很好理解吧。 看到这,你还犹豫什么呢?继续在code的世界里面遨游吧。没有解决不了的问题哈!加油! AMFPhp Flex3 交互(二) -- 一个带有 DataGrid 稍微复杂的例子 今天我们做一个稍微复杂的例子,在这个例子中,我们将要用到 ArrayCollection 作为返回的结果。在这个例子中,我们可爱的 remote 方法将会返回一个数组,数组中的值哪来的呢,就是在 Person 类里面的属性,呵呵。 首先在我们的本地服务大本营, D:\php\amfphp\services ( 为啥这个是大本营啊,去看看教程的第一节,呵呵 ) ,建立一个叫做tutorials( 认识这个单词吗?它是 指南 的意思,我又学会了个单词 ) 的目录,我们今天要在这个目录里写一些 php 文档。废话不多说,上代码!建立一个叫做 Person.php 的文档。代码如下:  1. <?php 2. class Person 3. { 4.     var $firstName; 5.     var $lastName; 6.     var $phone; 7.     var $email; 8.     // explicit actionscript package 9.     var $_explicitType = "tutorials.Person"; 10. } 11. ?> 复制代码 在这里面我们看到这样一个变量$_explicitType ,这位老兄是干什么的呢?他是告诉 amfphp 老大,这个类是与flash中的 tutorials.Person (注意,这里的这个类是在 flash 中的,我们还没有建立,马上我们就要创建它)这个类等价的。好,既然你告诉 amfphp 老大有这个类了,那就要建立一个啊,要不被老大揍可不是闹着玩的。 好,上一节我们已经建立了一个工程,我们就还用那个工程吧,点击打开 src文件夹,右键新建一个文件夹,起名字叫做tutorials,在这个文件夹中再建立一个 Person.as 文件。好,把下面的代码拷贝进去。  1. package tutorials 2. { 3.     [RemoteClass(alias="tutorials.Person")] 4.     [Bindable] 5.     public class Person 6.     { 7.         public var firstName:String; 8.         public var lastName:String; 9.         public var phone:String; 10.         public var email:String; 11.     } 12. } 复制代码 代码很简单吧,就是一个叫着 Person 的类,他有 4 个公共属性。 回到 我们的大本营  D:\php\amfphp\services  ,在 tutorials 目录中新建一个 PersonService.php 的文档,把下面的代码拷贝进去。  1. <?php 2. 3. require_once "./Person.php"; 4. 5. 6. class PersonService 7. { 8.     /** 9.      * Get a list of people 10.      * @returns An Array of Person 11.      */ 12.     function getList() 13.     { 14.         $people = array( 15.             array("Alessandro", "Crugnola", "+390332730999", "alessandro@sephiroth.it"), 16.             array("Patrick", "Mineault", "+1234567890", "patrick@5etdemi.com"), 17.         ); 18. 19.         $p = array(); 20. 21.         for($a = 0; $a < count($people); $a++) 22.         { 23.             $person = new Person(); 24.             $person->firstName = $people[$a][0]; 25.             $person->lastName = $people[$a][1]; 26.             $person->phone = $people[$a][2]; 27.             $person->email = $people[$a][3]; 28.             $p[] = $person; 29.         } 30. 31.         return $p; 32.     } 33. } 34. 35. ?> 复制代码 在 getList函数中,有一个保存人信息的数组 people ,然后我们做一个循环,把这些信息交给 person person 是我们通过 Person 新找的一个对象)这个对象的属性中,然后我们把 person 对象装进 p 这个箱子 ( 数组 ) 中,然后返回 p Ok 啦,代码也很好理解,对不对? 好了,最后一步了,在工程中的 src 目录里,右键点击 src ,新建一个叫做DataGrid.mxml  MXMLApplication 的文件吧。工程如图: 调到 source 模式,拷贝以下代码。  1. <?xml version="1.0" encoding="utf-8"?> 2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF"> 3.     <mx:RemoteObject id="myservice" source="tutorials.PersonService" destination="amfphp" fault="faultHandler(event)" showBusyCursor="true"> 4.         <mx:method name="getList" result="getListHandler(event)" fault="faultHandler(event)" /> 5.     </mx:RemoteObject> 6.     <mx:DataGrid x="10" y="10" width="345" id="people_list" dataProvider="{dp}" change="changeHandler(event)"> 7.         <mx:columns> 8.             <mx:DataGridColumn headerText="Last name" dataField="lastName"/> 9.             <mx:DataGridColumn headerText="First name" dataField="firstName"/> 10.             <mx:DataGridColumn headerText="Telephone" dataField="phone"/> 11.             <mx:DataGridColumn headerText="Email" dataField="email"/> 12.         </mx:columns> 13.     </mx:DataGrid> 14. 15.     <mx:Script> 16.         <![CDATA[ 17.             import mx.utils.ArrayUtil; 18.             import tutorials.Person; 19.             import mx.collections.ArrayCollection; 20.             import mx.rpc.events.ResultEvent; 21.             import mx.controls.Alert; 22.             import mx.rpc.events.FaultEvent; 23. 24.             [Bindable] 25.             private var dp:ArrayCollection; 26. 27.             [Bindable] 28.             private var selectedPerson:Person; 29. 30.             private function faultHandler(fault:FaultEvent):void 31.             { 32.                 Alert.show(fault.fault.faultString, fault.fault.faultCode.toString()); 33.             } 34. 35.             private function getListHandler(evt:ResultEvent):void 36.             { 37.                 dp = new ArrayCollection( ArrayUtil.toArray(evt.result) ); 38.             } 39. 40.             private function changeHandler(event:Event):void 41.             { 42.                 selectedPerson = Person(people_list.selectedItem); 43.                // Alert(selectedPerson); 44.             } 45.         ]]> 46.     </mx:Script> 47.     <mx:Button x="290" y="357" label="get list" click="myservice.getOperation('getList').send();"/> 48.     <mx:Form x="10" y="174" width="345" height="175"> 49.         <mx:FormHeading label="Selected Person" /> 50.         <mx:FormItem label="First Name"> 51.             <mx:TextInput id="person_first_name" text="{selectedPerson.firstName}" /> 52.         </mx:FormItem> 53.         <mx:FormItem label="Last Name"> 54.             <mx:TextInput id="person_last_name" text="{selectedPerson.lastName}" /> 55.         </mx:FormItem> 56.         <mx:FormItem label="Telephone"> 57.             <mx:TextInput id="person_phone" text="{selectedPerson.phone}" /> 58.         </mx:FormItem> 59.         <mx:FormItem label="Email"> 60.             <mx:TextInput id="person_email" text="{selectedPerson.email}" /> 61.         </mx:FormItem> 62.     </mx:Form> 63. </mx:Application> 复制代码 哈哈。运行一下,是不是这个界面。 是?点击 getlist 按钮,看有 DataGrid 里有信息出现吗?有!点击 DataGrid 有信息的任何一行。地下的文本框有信息显示吗? ! 你又成功了 ! 在编程的道路上又迈出了坚实的一步。加油啊,天才!代码是啥意思呢?天才,先自己分析一下。明天继续。 来吧,一起分析一下代码吧。 关于<mx :RemoteObject>标签里的内容,上一节已经说过了,什么!忘记了?点击这个链接看看吧。 http://bbs.actionscript3.cn/thread-16541-1-1.html 下面来说一下DataGrid标签里面的东东,这里面唯一需要注意的就是dataProvider="{dp}" ,这个,他是为DataGrid提供数据的源头,所以一定要有,否则DataGrid找不到数据。 因为我们返回的dp是一个数组,因此GataGrid会自动把信息加上,但是一定要注意,dataField的名字一定要和数组里属性的名字一样啊。很聪明吧? 然后是change事件,这个事件表示的当我们点击DataGrid的时候,即选择DataGrid条目的时候,响应的一个事件函数。函数在哪呢?往下看,在as3脚本里,是不是看到了一个private的changeHandler函数啊,当我们点击DataGrid的条目的时候,我们会把点击的那个条目强制转化为Person类型的对象,并把这个对象传递给selectedPerson,这样在下面的TextInput里面我们就可以用selectedPerson的属性来赋值了,怎么样?也很简单吧! 其他的如果不明白ArrayCollection等等这些的话,开始查找帮助文档吧。那里有我们要的一切。

转载于:https://www.cnblogs.com/gxldan/archive/2011/11/19/4066757.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值