Actionscript 3 flash.utils.IExternalizable+;远程处理&x2B;弹性误差#2004

Actionscript 3 flash.utils.IExternalizable+;远程处理&x2B;弹性误差#2004,actionscript-3,apache-flex,blazeds,weborb,netconnection,Actionscript 3,Apache Flex,Blazeds,Weborb,Netconnection,有一个客户机-服务器基本应用程序。客户端使用简单的远程处理与服务器端通信。服务器端可以使用WebORB、BlazeDS或任何其他产品。客户端正在使用FLEX框架。这就是关于技术堆栈的问题。现在,让我们忘掉服务器端,看看下面的客户端 package com.blog.ri { import mx.collections.ArrayCollection; public class MyCollection extends ArrayCollection {

有一个客户机-服务器基本应用程序。客户端使用简单的远程处理与服务器端通信。服务器端可以使用WebORB、BlazeDS或任何其他产品。客户端正在使用FLEX框架。这就是关于技术堆栈的问题。现在,让我们忘掉服务器端,看看下面的客户端

package com.blog.ri
{
    import mx.collections.ArrayCollection;

    public class MyCollection extends ArrayCollection
    {
        public function MyCollection(source:Array=null)
        {
            super(source);
        }
    }   
}
另外,假设我们有以下类,并且它被映射到服务器端类:

package com.blog.ri
{
    [Bindable]
    [RemoteClass(alias="com.blog.ri.MyEntity")]
    public dynamic class MyEntity
    {   
        private var _myCollection:MyCollection;

        public function get myCollection():MyCollection
        {
            if(_myCollection == null)
                _myCollection = new MyCollection();

            return _myCollection;
        }

        public function set myCollection(value:MyCollection):void
        {
            _myCollection = value;
        }       
    }
}
此外,服务器端服务为客户端公开了void save(MyEntity候选)方法,我在客户端实现了它,如下所示:

package com.blog.ri
{
    public class MyService
    {       
        private var _remoteObject:RemoteObject;

        public function MyService()
        {
            var channelSet:ChannelSet = new ChannelSet();
            var amfChannel:AMFChannel = new AMFChannel("my-amf", "http://localhost/weborb.aspx");
            channelSet.addChannel(amfChannel);

            _remoteObject  = new RemoteObject("GenericDestination");
            _remoteObject.channelSet = channelSet;
            _remoteObject.source = "com.blog.ri.MyService";
            _remoteObject.getDetailedStatistic.addEventListener("result",onItemSaved);
            _remoteObject.addEventListener("fault", onFault);
        }

        public function save(candidate:MyEntity, responder:IResponder = null ):void
        {
            var asyncToken:AsyncToken = _remoteObject.save(candidate);

            if( responder != null )
                asyncToken.addResponder( responder );
        }

    }
} 
protected function creationCompleteHandler():void
            {
                var myService:MyService = new MyService();

                var candidate:MyEntity = new MyEntity();
                candidate.myCollection = new MyCollection();

                myService.save(candidate);
            }
最后,我尝试在主mxml文件中保存MyEntity类的一个新实例,如下所示:

package com.blog.ri
{
    public class MyService
    {       
        private var _remoteObject:RemoteObject;

        public function MyService()
        {
            var channelSet:ChannelSet = new ChannelSet();
            var amfChannel:AMFChannel = new AMFChannel("my-amf", "http://localhost/weborb.aspx");
            channelSet.addChannel(amfChannel);

            _remoteObject  = new RemoteObject("GenericDestination");
            _remoteObject.channelSet = channelSet;
            _remoteObject.source = "com.blog.ri.MyService";
            _remoteObject.getDetailedStatistic.addEventListener("result",onItemSaved);
            _remoteObject.addEventListener("fault", onFault);
        }

        public function save(candidate:MyEntity, responder:IResponder = null ):void
        {
            var asyncToken:AsyncToken = _remoteObject.save(candidate);

            if( responder != null )
                asyncToken.addResponder( responder );
        }

    }
} 
protected function creationCompleteHandler():void
            {
                var myService:MyService = new MyService();

                var candidate:MyEntity = new MyEntity();
                candidate.myCollection = new MyCollection();

                myService.save(candidate);
            }
就是这样。运行代码时,我收到以下异常:

ArgumentError:错误#2004:其中一个参数无效。在 flash.net::NetConnection/invokeWithArgsArray()位于 flash.net::NetConnection/call()位于 mx.messaging.channels::NetConnectionChannel/internalSend()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:281] 在 mx.messaging.channels::AMFChannel/internalSend()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:364] 在 mx.messaging::Channel/send()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1002] 在 mx.messaging.channels::PollingChannel/send()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.as:394] 在 mx.messaging::ChannelSet/send()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1429] 在 mx.messaging::ChannelSet/channelConnectHandler()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\ChannelSet.as:1084] at flash.events::EventDispatcher/dispatchEventFunction()at flash.events::EventDispatcher/dispatchEvent()位于 mx.messaging::Channel/connectSuccess()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\Channel.as:1148] 在 mx.messaging.channels::AMFChannel/resultHandler()[E:\dev\hero\u private\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:576]

如您所见,我扩展了ArrayCollection类,根据Adobe文档,ArrayCollection实现了。我决定将问题本地化,并创建了一个实现IExternalizable的简单类。然后,我在其他一些MyChild类中扩展了这个类,并在MyEntity类中定义了MyChild属性。在本例中,我也收到了上面的异常。我是如何编写代码的,还是flex中存在错误

谢谢你的帮助。
这个问题重复出现在我的博客中。

尝试为MyCollection添加别名


直到我所有实现IExternalizable的类都有别名,我才得到了这个无用的错误#2004。在我的例子中,这是为了持久性(ViewNavigatorApplicationBase.persistNavigatorState=true),在这种情况下,我必须确保在启动时调用registerClassAlias的时间足够早,以便在View.deserializeData()之前调用。应用程序上的预初始化事件工作正常。

尝试为MyCollection添加别名

直到我所有实现IExternalizable的类都有别名,我才得到了这个无用的错误#2004。在我的例子中,这是为了持久性(ViewNavigatorApplicationBase.persistNavigatorState=true),在这种情况下,我必须确保在启动时调用registerClassAlias的时间足够早,以便在View.deserializeData()之前调用。应用程序上的预初始化事件工作正常。

您可以尝试:

            registerClassAlias( "mx.collections.ArrayCollection", ArrayCollection);
            registerClassAlias("flex.messaging.io.ArrayCollection", ArrayCollection);
你可以试试:

            registerClassAlias( "mx.collections.ArrayCollection", ArrayCollection);
            registerClassAlias("flex.messaging.io.ArrayCollection", ArrayCollection);

正在(反)序列化的某些类可能没有链接到Flex项目中。尝试将以下内容添加到主应用程序/模块文件:

private var forceReference:Array = [YourClass1, YourClass2];

正在(反)序列化的某些类可能没有链接到Flex项目中。尝试将以下内容添加到主应用程序/模块文件:

private var forceReference:Array = [YourClass1, YourClass2];

他已经在做这件事了,这就是他要做的。或者至少,这是它应该做的(我现在遇到了一个问题,
RemoteClass
似乎不起作用……)他只为我的实体做这件事,因此我建议我也为MyCollection做这件事。他已经在做这件事了,这就是为什么。或者至少,这是它应该做的(我现在遇到了一个问题,
RemoteClass
似乎不起作用……)他只是为了MyEntity做这件事,因此我建议也为MyCollection做这件事。