A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Problem implementing iExternalizable

  1. #1
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349

    Problem implementing iExternalizable

    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:
    code:

    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:
    code:

    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:
    Code:
    ArgumentError: Error #2004: One of the parameters is invalid.
    	at flash.utils::ByteArray/writeObject()
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    lel, F() function doesn't have arguments when defined, but does when called.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    wrong

  4. #4
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  5. #5
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    F never get call in code, not matter no arg

  6. #6
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    That's true Terrencing. I posted that reply randomly the day of my birthday haha, I just passed by to see if someone was online I was trying to have fun... I checked the code 2 days ago and I realized that F function was never called. Then I tried the code and I realized the issue. I removed the "Foo implements IExternalizable" part and it worked, so I guess that we can not write an external interface into a bytearray... so I read about the IExternalizable class and I discovered that we need to make a public method to write the desired data into a byte array and then we simply return that byte array instance...
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  7. #7
    Senior Member
    Join Date
    Aug 2012
    Posts
    115
    ok , may you post code used or .fla and .as files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center