这是我的第一个 flex 应用程序,我编写了一个 php 类,目的是从数据库中获取结果。该服务确实有效,但我很难让 Flash 列出结果,并且不明白如何从 Flash 中正确调用该函数。
继承人的PHP:
<?php
class CityService {
public function getCitys($q) {
$con = mysqli_connect('host', 'user', 'password','database') or die(mysqli_connect_error());
$sql="SELECT * FROM city WHERE countrycode ='".$q."'";
$result = mysqli_query($con, $sql) or die('query Failed: ' . mysqli_error($con));
$rows = array();
while($row = mysqli_fetch_object($result)) {
$rows[] = $row;
}
return $rows;
}
}
?>
然后我尝试在 flash 中选择函数并根据 $q 给出的值显示结果,但是 flash 不显示结果,当我设置服务时,它都显示它正在工作并且可以在生成器中返回结果但是当我尝试设置所有内容mxml
然后运行它时,我什么也得不到
这是包含所有相关部分的 flash mxml 示例:
<fx:Script><![CDATA[
import com.adobe.serializers.utility.TypeUtility;
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function button_clickHandler_100():void
{
currentState='data';
}
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
{
getCitysResult.token = cityservice.getCitys('GB');
}
]]></fx:Script>
<s:states>
<s:State fc:color="0x0003a3" name="europe"/>
<s:State name="data" fc:color="0x0081cc"/>
</s:states>
<fx:Declarations>
<s:CallResponder id="getCitysResult"/>
<cityservice:Cityservice id="cityservice" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
</fx:Declarations>
<s:Button click="button_clickHandler_100()" id="button128" includeIn="europe" skinClass="components.englandButton" x="101" y="135"/>
<mx:DataGrid includeIn="data" x="23" y="37" id="dataGrid" creationComplete="dataGrid_creationCompleteHandler(event)" dataProvider="{getCitysResult.lastResult}">
<mx:columns>
<mx:DataGridColumn headerText="citycode" dataField="citycode"/>
<mx:DataGridColumn headerText="id" dataField="id"/>
<mx:DataGridColumn headerText="countrycode" dataField="countrycode"/>
<mx:DataGridColumn headerText="city" dataField="city"/>
</mx:columns>
</mx:DataGrid>
我在这里错过了什么吗?除了设计层的其余部分,我是否正确地赋予了城市 php 服务的价值?我如何将 GB 绑定到按钮并以这种方式将其提供回城市功能?当我转到页面时,我也没有得到任何结果的主要问题???
这是动作脚本:
package services.cityservice
{
public class Cityservice extends _Super_Cityservice
{
}
}
还有 getCitys 函数
package services.cityservice
{
import com.adobe.fiber.core.model_internal;
import com.adobe.fiber.services.wrapper.RemoteObjectServiceWrapper;
import com.adobe.serializers.utility.TypeUtility;
import mx.rpc.AbstractOperation;
import mx.rpc.AsyncToken;
import mx.rpc.remoting.Operation;
import mx.rpc.remoting.RemoteObject;
import valueObjects.Citydata;
import mx.collections.ItemResponder;
import com.adobe.fiber.valueobjects.AvailablePropertyIterator;
[ExcludeClass]
internal class _Super_Cityservice extends com.adobe.fiber.services.wrapper.RemoteObjectServiceWrapper
{
// Constructor
public function _Super_Cityservice()
{
// initialize service control
_serviceControl = new mx.rpc.remoting.RemoteObject();
var operations:Object = new Object();
var operation:mx.rpc.remoting.Operation;
operation = new mx.rpc.remoting.Operation(null, "getCitys");
operation.resultElementType = valueObjects.Citydata;
operations["getCitys"] = operation;
valueObjects.Citydata._initRemoteClassAlias();
_serviceControl.operations = operations;
_serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
_serviceControl.source = "cityservice";
_serviceControl.endpoint = "gateway.php";
destination = "cityservice";
model_internal::initialize();
}
public function getCitys(q:Object) : mx.rpc.AsyncToken
{
var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("getCitys");
var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(q) ;
return _internal_token;
}