Using RemoteObject (AMF) from a Flash or Pure AS3

2019-06-28 08:45发布

问题:

I recently ported some code from a Flex project over to a new pure AS3 project. When i attempted to make an AMF call, I am getting an error message like this:

TypeError: Error #1034: Type Coercion failed: cannot convert Object@5425371 to mx.messaging.messages.ErrorMessage.

There was no stack trace associated with the error, so debugging was difficult.

I tried all manner of things (checking that all required libraries from the flex framework were included, etc) but nothing worked.

回答1:

After some time i found the answer: Flex does some initialization on startup which the AMF classes will not function without. Luckily Adobe has thought of those who want to use AMF from a non-flex project, or from flash, and have provided a method for doing the initialization required by AMF.

I added this line to the start of my application, and suddenly all AMF calls worked as well as they did in my Flex project:

RpcClassAliasInitializer.registerClassAliases();

(Yeah, i answered my own question. I didn't find any blogs or search results for this problem, so i'm sharing the problem and fix here.)



回答2:

I know this is a bit late of a response, but couldn't you have also used flash.net.registerClassAlias? Seems like RpcClassAliasInitializer is part of the mx.utils package which is still part of the Flex library.