0

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

3
  • rest variable doesn't work - the parameter following the rest variable must be of array data type. Commented Jun 16, 2011 at 11:22
  • 1
    I'm not sure i follow what your problem is, can you post some code? Commented Jun 16, 2011 at 12:04
  • if you've identified a problem being legacy code that doesn't follow the oop paradigm you should consider a rewrite. Commented Jun 16, 2011 at 12:09

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have my custom classes in the same directory. I simply meant that importing the class explicitly makes no difference. I must apologise, it has been over 8 months since I was programming regularly in AS3, I've been GTK++ in linux recently.
I think that the problem exists because the compiler isn't aware of the parametered class that is passed in because it hasn't compiled it at the time that the first class is declared and compiled. I think that this makes sense because the class is recognised as a valid type in other places later on in the order of execution with no complaints. I'm kind of scratching my head as I would prefer to type the parameter properly rather than leaving it typed as an asterisk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.