James
James

Reputation: 1

Actionscript 3 - passing custom class as parameter to custom class where parameter class not constructed

Hi and thanks in advance, I have a custom class being constructed from my main class. In the custom class it has another custom class that is passed in as a parameter. I would like to strictly type the parameter variable but when I do, 'the type is not a compile type constant etc'. This, I understand, is because the custom class used as a parameter has not yet been constructed. It all works when I use the variable type ( * ) to type the parameter. I suspect this is a design flaw, in that I am using an incorrect design pattern. It is actually hand-me-down code, having received a large project from someone else who is not entirely familiar with oop concepts and design patterns. I have considered using a dummy constructor for the parametered class in my main class but the passed in class also takes a custom class (itself with a parametered constructor). I am considering using ... (rest) so that the custom classes' parameters are optional. Is there any other way to control the order of construction of classes? Would the rest variables work? Thanks

(edit) in main.as within the constructor or another function

var parameter1:customclass2;

customclass1(parameter1);

in customclass1 constructor:

public function customclass1(parameter1:customclass2) { ....

Flash complains that the compiled type cannot be found when I use the data type customclass 2 in the paramater. It does not complain when I use the variable data type * or leave out the data type (which then defaults to * anyway). I reason that this is because customclass2 has not yet been constructed and is therefore not available to the compiler. Alternatively, I have not added the path of customclass2 to the compiler but I am fairly certain I have ruled this out. There are over 10,000 lines of code and the whole thing works very well. I am rewriting simply to optimise for the compiler - strict data typing, error handling, etc. If I find a situation where inheritance etc is available as an option then I'll use it but it is already divided into classes (at least in the main part). It is simply for my own peace of mind and to maintain a policy of strict data typing so that compiler optimization works more efficiently. thnx

Upvotes: 0

Views: 397

Answers (1)

Black Dynamite
Black Dynamite

Reputation: 4147

I have not added the path of customclass2 to the compiler but I am fairly certain I have ruled this out.

So if you don't have the class written anywhere what can the compiler do ? It is going to choke of course. You either have to write the CustomClass class file or just use "thing:Object" or "thing:Asteriks". It's not going to complain when you use the "*" class type because it could be anything an array, string, a previously declared class. But when you specify something that doesn't exists it will just choke, regardless of the order the parameters are declared in.

Upvotes: 1

Related Questions