I get error
Error #2099: The loading object is not sufficiently loaded to provide this information
when I try to encode object into JSON using as3corelib.
I succeeded encoding some value object which has no parent or children so I know that library works and that problem might be related to addChild or something like that. That is just guess.
Board is added to stage like that:
stage.addChild(board);
When I don’t add board to stage and try to serialize it I get different error:
undefined
at XML/http://adobe.com/AS3/2006/builtin::copy()
at global/describeTraits()
at global/avmplus::describeType()
at global/flash.utils::describeType()
...
Board class:
public class Board extends Sprite
{
public var board:Array;
public var blockColor:uint = 0xE3E3E3;
public var blockLength:uint
public function Board(blockLength:uint)
{
super();
x = 0;
y = 0;
this.blockLength = blockLength;
//buttonMode = true;
// Setting up two dim array
board = new Array(10);
for (var k:int = 0; k < board.length; k++)
{
board[k] = new Array(10);
}
for (var i:int = 0; i < 10; ++i)
{
for(var j:int = 0; j < 10; ++j)
{
var block:Block = new Block(i*blockLength, j*blockLength);
board[i][j] = block;
this.addChild(block); // here I add children
block.drawBlock(blockLength, blockColor);
block.addEventListener(MouseEvent.CLICK, blockClicked);
}
}
}
....
}
}
Here is code for Block, really nothing there.
public class Block extends Sprite
{
public var cos:int = 5; // test
public function Block(x:uint, y:uint)
{
...
}
public function drawBlock(length:uint, color:uint):void
{
...
}
}
Any clues why is that?
I would suggest that you don’t try to serialize any form of
DisplayObject; instead you should just be serializing the underlying Data (attributes) which the View uses; it’s hard to give you an exact answer from the code above, but consider the following:With the example above you would just serialize the
BlockViewModelobject when you want to save state, eg:You could then re-create a new BlockView by deserializing the data:
You could extend this further by moving the object construction / population logic into a Factory method to help separate the logic.