How to use IExternalization?

I want to save the state of the application which contains some interface components as shown in the image.

enter image description here

When the user leaves edit mode, the work must be saved in some form so that the user can edit later.

I cannot get data from sharedObject

.

Instead, now I would like to use IExternalization

. How do I use this to keep the user working?

+3


source to share


1 answer


This question contains an example of using IExternalizable.

You have multiple UIComponents descendants, maybe they even share a parent. So you take each of the classes and write what they implements IExternalizable

are and write a couple of coherent methods writeExternal

and readExternal

, keeping only the properties you need (x, y, type, whatever). Let's say resistor, you store your x, y, type as an enum or String, maybe rotation and that's it. When you do the implementation readExternal

, you read all the values ​​in the same order in which you wrote them, and then you restore everything and everything within the object from the values ​​you read. Anything external to an object must be restored by its parent, which will write a set of these objects (resistors, inductors, transistors, etc.) one by one and then willaddChild()

them when reading. complex enough structure, but will work if done properly.



Yes, all of this can be stored inside a SharedObject with its available methods. However, be careful, you will need to call the method registerClassAlias

on all the classes participating in the IExternalizable implementation.

0


source







All Articles