Hello everyone. I was testing this little prototype method I made up (in a file, Array_Update.as) (I do realize I could’ve used “for each…in” instead of “for…in”, but I just didn’t…),
Array.prototype.update = function(model:Array, prop1:String, prop2:String):void {
var i:String;
var j:String;
sub: for (i in this) {
for (j in model) {
if (model[j][prop2] == this*[prop1]) {
continue sub;
}
}
this.splice(this.indexOf(this*), 1);
}
add: for (j in model) {
for (i in this) {
if (model[j][prop2] == this*[prop1]) {
continue add;
}
}
this.push(model[j]);
}
}
in this class (in the same directory as Array_Update.as):
package com.cation.apps.demos {
import flash.display.Sprite;
[SWF(backgroundColor="#000000",width="200",height="200")]
public class Demo extends Sprite {
public function Demo() {
include "Array_Update.as";
var firstArray:Array = [
{x: 0},
{x: 1},
{x: 2, y: 1},
{x: 3, z: 0}
];
var secondArray:Array = [
{x: -1},
{x: 1},
{x: 2, y: 2},
{x: 4}
];
firstArray.update(secondArray, "x", "x");
}
}
}
The result should be:
firstArray = [
{x: -1},
{x: 1},
{x: 2, y: 1},
{x: 4}
];
It makes perfect sense to me, and should work, but whenever I compile it, it gives me a runtime error:
VerifyError: Error #1068: int and * cannot be reconciled.
at ()
at com.cation.apps.demos::Demo$iinit()[..\com\cation\apps\demos\Demo.as:19]
(I replaced some of the directory with “…”).
Array.prototype.update basically takes an array as an argument, and two string representations of properties to be compared and “updates itself”
That means it will remove any elements with a property value the model array’s own elements don’t have, and add any elements with properties from the model that its own elements don’t have, without touching any elements with matching values.
Maybe it doesn’t have many applications but the real problem is it gives that runtime error above. I don’t understand what’s wrong.
This is the compiled SWF, http://img252.imageshack.us/my.php?image=demooi7.swf
Any help is appreciated.