This content has been marked as final. Show 9 replies
I am not really sure if I understand your question. However, will the code below help you?
That's not what I meant.
Given any array, a, and constructor, c, can we get:
x = new c(a,a,a,...,a[a.length]);
That a.length should be a.length-1
Interesting. There's nothing I know of. I assume you've tried using apply() on the class constructor?
Yup, I've tried that already.
I'm doing this, because I'm trying to come up with a way to write ActionScript in an external document, and then have Flash load and excecute it. To make things easier, I'm using XML, but I can't get my head around making constructors work.
I could always simply have: new c(a,a,a,a,...,a)
and just hope that the number of parameters does not exceed 20 (which is pretty likely)
Neat. I tried making an AS parser that wasn't XML based, it was completely string parsing, I didn't get very far :-)
Seems like there should be a way to do what you want, but I sure can't think of it. You're workaround seems fine though, I've used that for functions before I knew about Funcion.apply(). That won't work in AS3, though, because functions/constructors need to recieve the expected number of arguments or they throw an error.
Good luck, would love to see the final product if you feel like sharing!
I thought about this idea like a year ago, but I never actually tried it out. My XML based AS is going to be longer than the normal ActionScript, and slower.
The following does the equivalent of: req_txt.text = req_txt.text+'abc';
That's cool. One part that really tripped me up was handling conditionals. But I guess when using XML it's really just more of the same, with nodes blocked out for the different conditions.
BTW, I may misunderstand, but using apply() on the constructor seems to work in most cases:
var args = [1,2,3,4];
var a = new myClass();
a.constructor.apply(a,args); //myClass constructor traces args
var num = new Number();
var args = ;
num = num.constructor.apply(num,args);
I couldn't get it to work with BitmapData, partly because attempting to instantiate a BitmapData without args fails, and even if you put in 1,1 for width/height, the constructor.apply() doesn't seem to work.
var bmp = new flash.display.BitmapData();
var args = [mc._width,mc._height,true,0];
Seems like there would be other problems, though, like constructors going off twice would likely cause problems with some classes, so your workaround seems much safer.
AH, I didn't try that.Thanks
For conditions/loops, try..catch..finally seems rather useful.