Domanda

sto usando AMFPHP 1.9, ActionScript 3 e Adobe Flash Pro CS5 con Flash player 10x. Stavo cercando di ottenere i dati chiamando AMFPHP serices. Sono in esecuzione l'applicazione dall'interno l'IDE Flash.

Per i tipi primitivi come stringa o interi va bene lavorare. Ma quando si cerca di ottenere un oggetto personalizzato che mostra il seguente errore:

SecurityError: Errore # 2000:. Nessun contesto di protezione attiva

E il parametro nella funzione di gestore di risultato contiene nullo. Mi sono perso qualcosa qui? Si prega di aiuto.

In seguito sono le mie classi:

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) ;
        }
}

e qui di 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:
    }
}
?>

Ecco come io chiamo il servizio:

var sceneService:SceneService = new SceneService();
sceneService.getSceneByID(1, getSceneByID_resultHandler, getSceneByID_faultHandler);

gestori:

    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);
    }
È stato utile?

Soluzione 2

@daidai: Grazie molto che si risposto. Ho pensato che questo posto sarebbe risiedere per sempre in profondità all'interno del database SOF senza risposta / non risponde e non vedere mai la luce. E poi, dopo 10 lunghi giorni, hai risposto :) ho aumentato la tua risposta, perché ci tenevi a rispondere. Grazie ancora una volta.

L'ho provato anche dal browser. Stesso risultato.

Ma ho finalmente capito il motivo per cui non funzionava diversi giorni indietro. Il problema è che, per qualche strano motivo (o di sicurezza), le classi AS3 personalizzato che ereditano da MovieClip (e immagino per tutte le classi di sistema) non può essere mappato dalle loro controparti PHP, nel mio caso, dalla classe Scene.php. Ma la classe AS3 può essere inviato alla classe di servizio PHP e essere mappato con successo. Ho dovuto portare in alcuni cambiamenti alla mia architettura per affrontare questo problema e risolto il mio problema. Ma questo problema in realtà mi ha messo sul bordo e ho mantenuto questo post sotto osservazione ogni ora per giorni nella speranza di qualche risposta.

In ogni caso, ho testato solo su Flash Player versione 10.1.82.76. Non so se funziona nelle versioni precedenti, non ho la prova su di loro.

Altri suggerimenti

Prova in esecuzione all'interno di un browser, ho trovato AMFPHP / Flash divertente agire all'interno dell'IDE.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top