Hi, I'm using AMFPHP 1.9, ActionScript 3 and Adobe Flash Pro CS5 with Flash player 10x. I was trying to get data by calling amfphp serices. I'm running the app from within the Flash IDE.
For primitive types like string or integer it's working fine. But when trying to get a custom object it shows the following error:
SecurityError: Error #2000: No active security context.
And the parameter in the result handler function contains null. Did I miss anything here? Please help.
Following are my classes:
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) ;
}
}
and here's 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:
}
}
?>
Here's how I call the service:
var sceneService:SceneService = new SceneService();
sceneService.getSceneByID(1, getSceneByID_resultHandler, getSceneByID_faultHandler);
Handlers:
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);
}