Search code examples
javaactionscript-3apache-flexred5coercion

TypeError: Error #1034: Type Coercion failed: cannot convert Object to Array


i have a Problem with the understanding of Sending Objects,Variable or else from my Red5 Java Server Application to a AS3 Script.

The Problem im Facing is that i wrote down the following code in Java:

        ((IServiceCapableConnection) conn).invoke("say", params);

It invokes a Method in my ActionScript that calls "say" with his Parameters called "params". So far so good.

My ActionScript looks like:

        public function say(user:Array):void{
            var usr:Array = user  as UserVO;
            list.appendText(usr[0] + "\n");
        }

So it gets the Array but i cant use it its tells me that cause the following Error:

TypeError: Error #1034: Type Coercion failed: cannot convert Object@123b4a7f1 to Array.

So can someone tell me how to "Convert" this Part right? i saw some Articles about serializing but didnt get the Problem.


Solution

  • UserVO isn't compatible with Array:

     var usr:Array = user  as UserVO;
    

    You may try this:

     var usr:UserVO = user[0] as UserVO;// or similar in a for loop
    

    It would be good if you verify following:

    Java:

    package abc;
    public class UserVO implements Serializable { .. }
    

    AS:

    [Bindable]
        [RemoteClass(alias="abc.UserVO")]
        public class UserVO 
        { .. }