title: AS3 - Problems with IExternalizable
body: <p>So, i've been working with ByteArrays a lot recently and i'm running into some annoying problems that make me want to rip my hair out.</p>
  
  <p>basically, i'm trying to save project data for an application that i'm making to compile characters for a game into one file. the project consists of custom objects, vectors, vectors of vectors, and even vectors of vectors of custom objects! i figured the best way to write all this data properly would be to use the IExternalizable interface with the readExternal and writeExternal commands. so here's what i'm doing.</p>
  
  <p>i write all the project data to an object, then write that object into a ByteArray, and save it to a file:</p>
  
  <pre><code>// probject means project object !
  mProbject= { };
  
  // Register vector as class, just to prevent any errors about that just in case
  registerClassAlias("vec_core.timeline.KeyFrame", Vector.&lt;KeyFrame&gt; as Class);
  
  // single KeyFrame Object
  mProbject.currentFrame = Main.getInstance().animationList.selectedItem.currentKeyFrame; 
  
  // a Vector.&lt;Vector.&lt;KeyFrame&gt;&gt;
  mProbject.frames = Main.getInstance().animationList.keyFrameVectorVector; 
  
  // an unsigned int
  mProbject.selectedItemIndex = Main.getInstance().animationList.entries.indexOf(Main.getInstance().animationList.selectedItem);  
  
  // Vector.&lt;String&gt;
  mProbject.animationNames = Main.getInstance().animationList.animationNames; 
  
  // String
  mProbject.projectPath = nativePath;
  
  //String
  mProbject.projectName = name; 
  
  mByteArray = new ByteArray();
  mByteArray.writeObject(mProbject);
  mByteArray.compress();
  
  return mByteArray;
  </code></pre>
  
  <p>inside the KeyFrame class though, there is two more vectors of custom objects:</p>
  
  <pre><code>private var mHitboxes:Vector.&lt;Hitbox&gt;;
  private var mHitboxSprites:Vector.&lt;HitboxSprite&gt;;
  </code></pre>
  
  <p>so i set up both of those classes and my KeyFrame class to use IExternalizable:</p>
  
  <pre><code>public class HitboxSprite extends Sprite implements IExternalizable
  {
      public function readExternal(input:IDataInput):void
      {
          trueBounds.x = input.readFloat();
          trueBounds.y = input.readFloat();
          trueBounds.width = input.readFloat();
          trueBounds.height = input.readFloat();
          mHitbox = input.readObject();
      }
  
      public function writeExternal(output:IDataOutput):void
      {
          output.writeFloat(trueBounds.x);
          output.writeFloat(trueBounds.y);
          output.writeFloat(trueBounds.width);
          output.writeFloat(trueBounds.height);
          output.writeObject(mHitbox);            
      }
  }
  
  
  public class Hitbox implements IExternalizable
  {
      public function readExternal(input:IDataInput):void
      {
          mName = input.readUTF();
          mType = input.readUnsignedInt();
          mEnabled = input.readBoolean();
          mKnockback = input.readBoolean();
          x = input.readFloat();
          y = input.readFloat();
          width = input.readFloat();
          height = input.readFloat();
         addMultipleTags(input.readUTF());
      }
  
      public function writeExternal(output:IDataOutput):void
      {
          output.writeUTF(mName);
          output.writeUnsignedInt(mType);
          output.writeBoolean(mEnabled);
          output.writeBoolean(mKnockback);
          output.writeFloat(mX);
          output.writeFloat(mY);
          output.writeFloat(mWidth);
          output.writeFloat(mHeight);
          output.writeUTF(getAllTags());
      }
  }
  
  public class KeyFrame implements IExternalizable
  {
      public function readExternal(input:IDataInput):void
      {
          mID = input.readUnsignedInt();
          mLabel = input.readUTF();
      }
  
      public function writeExternal(output:IDataOutput):void
      {
          output.writeUnsignedInt(mID);
          output.writeUTF(mLabel);
      }
  }
  </code></pre>
  
  <p>but when it gets to the writeObject() method of the "root" ByteArray, i get the error:</p>
  
  <pre><code>[Fault] exception, information=ArgumentError: Error #2004: One of the parameters is invalid.
  </code></pre>
  
  <p>this is probably the single most annoying problem i've ever had. it seems like i've tried everything and nothing is working.
  does anyone else have experience with this? am i doing something wrong??
  i'd appreciate any help i can get on this. i just wanna continue making my game :&lt;</p>