# ArgumentError: Error #2004 when implementing iExternalizable

**URL:** https://forum.kirupa.com/t/argumenterror-error-2004-when-implementing-iexternalizable/407196
**Category:** flash
**Created:** [December 4, 2014, 10:07pm UTC](https://forum.kirupa.com/t/argumenterror-error-2004-when-implementing-iexternalizable/407196 "2014-12-04T22:07:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sneakyimp](https://avatars.discourse-cdn.com/v4/letter/s/35a633/32.png) [@sneakyimp](https://forum.kirupa.com/u/sneakyimp)
#### Post date: [December 4, 2014, 10:07pm UTC](https://forum.kirupa.com/t/argumenterror-error-2004-when-implementing-iexternalizable/407196/1 "2014-12-04T22:07:22Z")

</div>

I’ve written a trivial class in attempting to better understand iExternalizable’s behavior. I can’t see that I’ve done anything wrong, but my code throws an error. Here’s my class:

```auto
package {
    import flash.utils.IDataInput;
    import flash.utils.IDataOutput;    
    import flash.utils.IExternalizable;

    public class Foo implements IExternalizable {
    
        private var A:String;
        public var B:String;
         
        function C(){
        }
         
        public function D(val:String):void {
            A = val;
        }
         
        public function E(val:String):void {
            B = val;
        }
         
        public function F():String {
            return A + " " + B;
        }
        
        public function writeExternal(output:IDataOutput): void {
            //output.writeInt(2);
            output.writeUTF(A);
            output.writeUTF(B);
        }
 
        public function readExternal(input:IDataInput): void {
            A = input.readUTF();
            B = input.readUTF();
        }
    }
}
```

This is the code on the first frame of my FLA:

```auto
var obj:Foo = new Foo();
obj.D("a");
obj.E("b");
var bytes: ByteArray = new ByteArray();
bytes.writeObject(obj);
```

and here’s the error that gets thrown:

```auto
ArgumentError: Error #2004: One of the parameters is invalid.
    at flash.utils::ByteArray/writeObject()
```

---

<div class="post-metadata">

### Author: ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)
#### Post date: [December 4, 2014, 11:28pm UTC](https://forum.kirupa.com/t/argumenterror-error-2004-when-implementing-iexternalizable/407196/2 "2014-12-04T23:28:01Z")

</div>

Are you using [registerClassAlias](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/package.html#registerClassAlias%28%29) before that?
