Ok, here is another one -- I really have to get back on flashcoders already!
As everyone knows, you can call a method in the regular way, and you can use 'call' or 'apply' (function methods). This works for built in types too, like movieclip -- the following both work and do the same thing:
_root.attachMovie("mc1", "mcInst", 99);
MovieClip.prototype.attachMovie.apply(_root, ["mc1", "mcInst", 99]);
these too:
_root.mc.duplicateMovieClip("mc2", 100);
MovieClip.prototype.duplicateMovieClip.apply(_root.mc, ["mc2", 100]);
But, this doesn't seem to work at all:
_root.mc.loadVariables("vars.txt"); // works fine
// broken of spades:
MovieClip.prototype.loadVariables.apply(_root.mc, ["vars.txt"]);
The error you get is:
Target not found: Target="/mc" Base="?"
I first thought it wasn't able to treat a movieclip like a function, but duplicateMovieClip works fine, so I'm not sure what is up. I've tested a few other methods and they seem to work, but unfortunately I may have to test every method in the api, as it is pretty critical we special case the ones that don't work (or find work arounds : ). Anyone know of other things that fail with Apply( )? Is there a way to make it come to it's senses?
We are wanting to use apply( ) in a lot of places, as it makes it much safer to reverse args (swf bytecode passes the args in reverse order, unlike IL and almost everything else). In spite of taking a bit of extra time to do that, it will work out good I think -- it allows us to just store all methods and types in array tables, and then (for the most part) just call them off their indexes. With this we can virutally eliminate the constant pool, so the whole thing gets a speed boost and makes the swf and memory footprint considerably smaller. But first, it has to all be working, even Mr. JerkFace loadVariables.
posted on Tuesday, February 08, 2005 1:52 AM