这个例子中,为什么flex 调用的时候 不按顺序就出错,就是说PHP中的差别就是
require('D:/EmpireServer/ecshop/amfphp-2.1.1/Amfphp/Services/BaseAttribute.php');
语句出现的顺序。
edit_GetMaterialType_sq.php
<?php
class edit_GetMaterialType_sq
{
function IsLogin($isadmin)
{
require('D:/EmpireServer/ecshop/amfphp-2.1.1/Amfphp/Services/BaseAttribute.php');
$reLogin = array();
$reLogin[] = 'IsLogin($isadmin)';
return $reLogin;
}
function get_materialtype()
{
$g = array();
$g[] = 'materialtype()' ;
return $g;
}
function get_templatetype($templateid,$userid)
{
require('D:/EmpireServer/ecshop/amfphp-2.1.1/Amfphp/Services/BaseAttribute.php');
$p = array();
$p[] = 'get_templatetype' ;
return $p ;
}
}
?>
BaseAttribute.php
<?php
class BaseAttribute
{
var $Width = 0;
var $Height = 0 ;
}
?>
在flex中这样调用测试的
example.mxml
<?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:halo="library://ns.adobe.com/flex/halo"
xmlns:mx="library://ns.adobe.com/flex/mx"
applicationComplete="application1_applicationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.remoting.RemoteObject; //RemoteObject,我认为相当于OLEDB的Connection,总的连接。
protected function application1_applicationCompleteHandler(event:FlexEvent):void
{
// 在程序加载的时候运行该事件
so.IsLogin(true) //注意这三行的顺序,不这样就出错
so.get_materialtype() //注意这三行的顺序,不这样就出错
so.get_templatetype(1,1) //注意这三行的顺序,不这样就出错
}
public function RemoteFaultss(re:FaultEvent,title:String):void
{
Alert.show("Message:" +re.fault.content+":"+re.fault.faultDetail,title);
}
public function IsLoginRemoteResultss(re:ResultEvent):void
{
Alert.show( re.result.toString())
}
public function RemoteFault(re:FaultEvent,title:String):void
{
Alert.show("Message:" +re.fault.content+":"+re.fault.faultDetail,title);
}
public function IsLoginRemoteResult(re:ResultEvent):void
{
Alert.show( re.result.toString())
}
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
}
public function RemoteFaults(re:FaultEvent,title:String):void
{
Alert.show("Message:" +re.fault.content+":"+re.fault.faultDetail,title);
}
public function IsLoginRemoteResults(re:ResultEvent):void
{
Alert.show( re.result.toString())
}
]]>
</fx:Script>
<fx:Declarations>
<s:RemoteObject id="so" destination="amfphp"
source="edit_GetMaterialType_sq">
<mx:method fault="{RemoteFaultss(event,'登录验证失败2')}" name="IsLogin"
result="{IsLoginRemoteResultss(event)}"/>
<mx:method fault="{RemoteFault(event,'登录验证失败')}" name="get_materialtype"
result="{IsLoginRemoteResult(event)}"/>
<mx:method fault="{RemoteFaults(event,'登录验证失败1')}" name="get_templatetype"
result="{IsLoginRemoteResults(event)}"/>
</s:RemoteObject>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
</s:Application>
------解决方案--------------------
你的 BaseAttribute.php 文件中是一个类定义
重复加载是会出错的!
require('D:/EmpireServer/ecshop/amfphp-2.1.1/Amfphp/Services/BaseAttribute.php');
应放在外面,不能放在方法里
------解决方案--------------------
方法里会起冲突