, poke:
, .
" . , ". . ActionScript , AMF ( ActionScript). AMF .
" , , , ..." , , , .
"... (.. )." . - , .
"[ ] ( , , )." , , . , . .
" , , ". , slice() concat() - , . , . , . , - - . - , .
: - ?
" - , , , ( )" , .
(Array.slice() Array.concat()) . . - (, , ), - . , , , , . , . , , .
, , . - - , .
, poke, . clone() . , , Array Dictionary, , , , , clone() , . . , : ( ); clone ( , clone).
- AMF , - , . - , -, .
var t:Array = [];
t[0] = [1, 2, 3];
t[1] = new Dictionary();
t[1]['hello'] = 'world';
t[2] = {'my': 'object'}
trace(t, t[1]['hello'], t[2]['my']); // [trace] 1,2,3,[object Dictionary],[object Object] world object
var t2:Array = clone(t);
trace(t2, t2[1]['hello'], t2[2]['my']); // [trace] 1,2,3,[object Dictionary],[object Object] world object
t[0] = [4, 5, 6];
t[1]['hello'] = 'earth';
t[2]['my'] = 'other object';
trace('modified values'); // [trace] modified values
trace(t, t[1]['hello'], t[2]['my']); // [trace] 4,5,6,[object Dictionary],[object Object] earth other object
trace(t2, t2[1]['hello'], t2[2]['my']); // [trace] 1,2,3,[object Dictionary],[object Object] world object
function clone(source:*):* {
var b:ByteArray = new ByteArray();
b.writeObject(source);
b.position = 0;
return(b.readObject());
}
1 . , .
, : mx.utils.ObjectUtil.
, , IExternalizable. :
public function writeExternal(output:IDataOutput):void
public function readExternal(input:IDataInput):void
, . , , . .
:
package {
import flash.utils.IExternalizable;
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.net.registerClassAlias;
public class Car implements IExternalizable {
private var type:String;
private var contents:Array;
public function Car() {
registerClassAlias("Car", Car);
}
public function setVars(type:String, contents:Array):void {
this.type = type;
this.contents = contents;
}
public function setType(type:String):void {
this.type = type;
}
public function writeExternal(output:IDataOutput):void {
output.writeUTF(type);
output.writeObject(contents);
}
public function readExternal(input:IDataInput):void {
type = input.readUTF();
contents = input.readObject();
}
public function toString():String {
return "[Car type = " + type + ", contents = " + contents + "]";
}
}
}
package {
import flash.utils.IExternalizable;
import flash.utils.IDataInput;
import flash.utils.IDataOutput;
import flash.net.registerClassAlias;
public class Person implements IExternalizable {
private var firstName:String;
private var secondName:String;
public function Person() {
registerClassAlias("Person", Person);
}
public function setVars(firstName:String, secondName:String):void {
this.firstName = firstName;
this.secondName = secondName;
}
public function writeExternal(output:IDataOutput):void {
output.writeUTF(firstName);
output.writeUTF(secondName);
}
public function readExternal(input:IDataInput):void {
firstName = input.readUTF();
secondName = input.readUTF();
}
public function toString():String {
return "[Person firstName = " + firstName + ", secondName = " + secondName + "]";
}
}
}
:
package {
import flash.display.Sprite;
import flash.utils.ByteArray;
import flash.utils.Dictionary;
public class Serial extends Sprite {
public function Serial() {
var person0:Person = new Person();
person0.setVars("John", "Doe");
var person1:Person = new Person();
person1.setVars("Jane", "Doe");
var car0:Car = new Car();
car0.setVars("Ford", [person0, person1]);
var person2:Person = new Person();
person2.setVars("Joe", "Bloggs");
var car1:Car = new Car();
car1.setVars("Vauxhall", [person2]);
var street:Array = [car0, car1];
trace("street = " + street);
var street2:Array = clone(street);
trace("street2 = " + street2);
person0.setVars("Max", "Headroom");
person1.setVars("Simon", "Le Bon");
car0.setType("Mini");
person2.setVars("Harry", "Wotsit");
car1.setType("Austin");
trace("modified values of street");
trace("street = " + street);
trace("street2 = " + street2);
}
private function clone(source:*):* {
var b:ByteArray = new ByteArray();
b.writeObject(source);
b.position = 0;
return(b.readObject());
}
}
}
. , - , .
, , .
:
- .
- , , , .
- . , , , . , , , , .
. Adobe : http://livedocs.adobe.com/flex/3/html/help.html?content=10_Lists_of_data_6.html
, Adobe Java.