Flex very strange casting error

119 Views Asked by At

I'm going mad with an error non error on my web-app Flex 3.6 based (using BlazeDS). I try to describe my issue: I have a java class:

public class User {...}

and the binding one in .as:

[Bindable]
[RemoteClass(alias="it.dto.User")]
public class User {...}

I also have a DataManager.as to do the Async call like this:

public function getUser():void {
    var token:AsyncToken = _service.getUser();
    token.addResponder(new AsyncResponder(userOnResult,userOnFault));
}
private function userOnFault(event:FaultEvent,token:Object):void {
    var _fail:String = "Error";
}
private function socOnResult(event:ResultEvent,token:Object):void {
    _resUser = event.result as ArrayCollection;
    dispatchEvent(new MyEvent("USER_EVENT",_resUser));
}

Now I implemented the following code in two different .as file (different package), which refers to two different .mxml:

var data:DataManager = new DataManager;
....
data.addEventListener("USER_EVENT",userResult);
....
data.getUser();
....
private function userResult(dataEvent:MyEvent):void {
    var user:ArrayCollection = new ArrayCollection;
    user = dataEvent.result as ArrayCollection;
    for (var i:int = 0;i<user.length; i++) {
        var u:User = new User;
        u = (User)(user.getItemAt(i));
    }
    _dm.removeEventListener("USER_EVENT",userResult);
}

The drama is that in the first .as it works perfectly, and in the second .as give me a Error of coercion failed. In the second file seems how it can't recognize the User class. Do you have any idea?? I'm going mad!! Thank you

@Stacktrace error:

TypeError: Error #1034: Type Coercion failed: cannot convert   appcode.dto::SocietaDTO@b4dbfc1 to appcode.dto.SocietaDTO.
at modules::ReportIspezioni/onSocResult()[D:\workspace\maga\aga\flex_src\modules\ReportIspezioni_src.as:80]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at appcode.dao::DataManager/socOnResult()[D:\workspace\maga\aga\flex_src\appcode\dao\DataManager.as:180]
at mx.rpc::AsyncResponder/result()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AsyncResponder.as:82]
at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:199]
at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:172]
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:199]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:263]
at mx.rpc::Responder/result()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:46]
at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
at NetConnectionMessageResponder/resultHandler()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:524]
at mx.messaging::MessageResponder/result()[C:\autobuild\3.x\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:199]

Obviusly the User class written above is just for example, to understand the code logic. The real class is a DTO calls SocietaDTO. N.B: The code works perfectly in another module of my project.. I don't understand why here it doesn't work.

Thanks a lot

1

There are 1 best solutions below

0
junior_developer On

I never save browser cache when developing.. Anyway I solve the Issue by adding this:

registerClassAlias("it.mec.dto.SocietaDTO", SocietaDTO);

In the class were exception launch.

Thanks anyway