-
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()
-
Designer, Programmer, Musician
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
-
-
Designer, Programmer, Musician
Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries
-
F never get call in code, not matter no arg
-
Designer, Programmer, Musician
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
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|