Search code examples
apache-flexremoteobject

in Flex 3.2 Having troubles converting remote object result to specific object on client side in modules


in Flex 3.2 Having troubles converting remote object result to specific object on client side in modules.

For example I have VIPSAdmin module.

it has function

private function doResult(event:ResultEvent):void {
var data_:Array = ArrayUtil.toArray(event.result); 
var result:ResultDTO = data_[0] as ResultDTO;
if(!result.isError()) {
    trace(result.result);
    vipsAdminDTO = result.result as VIPSAdmin;
    compId= vipsAdminDTO.compId; // second time dying here
}

}

Function invoked when I get data from remote objet.

First time all great,when I unload this modeule and load it again:

data_[0] as ResultDTO;

Performs fine, but

vipsAdminDTO = result.result as VIPSAdmin;

vipsAdminDTO always null!

Even when

trace(result.result);

produces [object VIPSAdmin]

What a heck I missing here!? Looks like it just cannot do

result.result as VIPSAdmin;

even when trace and debug says it is instance of VIPSAdmin


Solution

  • I've figured out what is the problem, problem is that when I first instantiate something in module then in main app, somehow classes are not alined even that they are identical !

    So solution is to make a fake instance in application class first, then if you use that same class to make an instance in module it will work!

    I do it very simple in my main application class I just added:

    VIPSAdmin;
    

    This seems to create some sort of ghost instance, which I belie will be pickup by GC later, but will build tables of instances properly! Which solved my problem.

    Not sure if this is appropriate solution ! but it sure works.