我正在將AMFPHP 1.9,ActionScript 3和Adobe Flash Pro CS5與Flash player 10x一起使用。我試圖通過調用amfphp服務來獲取數據。我正在Flash IDE中運行應用程序。AMFPHP:無法將PHP類映射到AS3類
對於類似字符串或整數的原始類型,它工作正常。但是當試圖獲取自定義對象時,它顯示以下錯誤:
SecurityError:錯誤#2000:沒有活動安全上下文。
而結果處理程序函數中的參數包含null。我在這裏錯過了什麼嗎?請幫忙。
以下是我的課:
ServiceContext.as
import flash.net.NetConnection;
import flash.net.ObjectEncoding;
import flash.events.NetStatusEvent;
internal class ServiceContext
{
protected var myService:NetConnection;
public function ServiceContext():void
{
myService = new NetConnection();
myService.objectEncoding = ObjectEncoding.AMF3;
myService.connect("http://localhost/MyApp/amfphp/gateway.php");
myService.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
}
private function onNetStatus(event:NetStatusEvent):void
{
trace(event.info);
}
}
SceneService.as
import com.ddr.cv.model.Scene;
import flash.net.Responder;
public class SceneService extends ServiceContext
{
public function SceneService():void
{
com.ddr.cv.model.Scene.register();
}
public function getSceneByID(sceneID:uint, resultHandler:Function, faultHandler:Function)
{
var responder = new Responder(resultHandler, faultHandler);
myService.call("com.ddr.cv.model.Scene.getSceneByID", responder, sceneID);
}
public function saveScene(scene:Scene, resultHandler:Function, faultHandler:Function)
{
var responder = new Responder(resultHandler, faultHandler);
myService.call("Scene.saveScene", responder, scene);
}
}
Scene.as
import flash.display.MovieClip;
import flash.net.registerClassAlias;
[RemoteClass(alias="com.ddr.cv.model.Scene")]
[Bindable]
public class Scene extends MovieClip
{
private var _id:uint;
public function get id():uint
{
return _id;
}
private var _sceneName:String;
public function get sceneName():String
{
return _sceneName;
}
private var _imageName:String;
public function get imageName():String
{
return _imageName;
}
private var _sceneCategoryID:int;
public function get sceneCategoryID():int
{
return _sceneCategoryID;
}
private var _userID:String;
public function get userID():String
{
return _userID;
}
private var _creationDate:Date;
public function get creationDate():Date
{
return _creationDate;
}
public function Scene(id:uint = 0, sceneName:String = null, imageName:String = null, sceneCategoryID:int = 0, userID:String = null, creationDate:Date = null):void
{
_id = id;
_sceneName = sceneName;
_imageName = imageName;
_sceneCategoryID = sceneCategoryID;
_userID = userID;
_creationDate = creationDate;
}
public static function register():void
{
registerClassAlias("com.ddr.cv.model.Scene", com.ddr.cv.model.Scene) ;
}
}
和這裏的Scene.php
<?php
class Scene {
var $id;
var $sceneName;
var $imageName;
var $sceneCategoryID;
var $userID;
var $creationDate;
// explicit actionscript package
var $_explicitType = "com.ddr.cv.model.Scene";
function Scene($id = 0, $sceneName = null, $imageName = null, $sceneCategoryID = 0, $userID = null, $creationDate = null)
{
$this->id = $id;
$this->sceneName = $sceneName;
$this->imageName = $imageName;
$this->sceneCategoryID = $sceneCategoryID;
$this->userID = $userID;
$this->creationDate = $creationDate;
}
function getSceneByID($id){
//creating dummy Scene object
$scene = new Scene(1, "Test Scene", "test_scene.jpg", 6, null, null);
return $scene;
}
function saveScene($scene)
{
//To Do:
}
}
?>
這是我如何調用該服務:
var sceneService:SceneService = new SceneService();
sceneService.getSceneByID(1, getSceneByID_resultHandler, getSceneByID_faultHandler);
處理程序:
public function getSceneByID_resultHandler(scene:com.ddr.cv.model.Scene):void
{
//scene contains null here.
//Shouldn't it contain the dummy Scene object from amfphp service method?
trace("Success: " + scene);
}
public function getSceneByID_faultHandler(fault:Object):void
{
trace(">>> fault:" + fault.description);
}