|
|
|
#1 |
|
Senior Member
Join Date: Jan 2006
Posts: 100
|
Hello all,
I need to create a custom Object that basically stores some custom parameters (properties?), which I have successfully done, and the code below works fine. PHP Code:
Anyway, I was wondering if it's a "best practice" to strict data type a custom objects' properties, and if so, how to do it in the logic above? I kept getting syntax errors when I just tried it initially. I know if I created a custom Class .AS file, I would be forced to data type the properties... but I'd rather just do it "in-line" in my main .FLA file. Also, I know I can just pass typed VARIABLES to the properties... but I'd rather have the properties strict-typed themselves... so if I try to pass a variable as the wrong type, then I would still get an error. Thanks! |
|
|
|
|
|
#2 |
|
Will moderate for beer
Join Date: Apr 2007
Location: Austin, TX
Posts: 5,253
|
Yes, it is best practice to create a class to represent your objects if you know that your objects should have a consistent and restricted set of properties/methods.
It is not possible to add these restrictions without creating a class. It is possible to create a 'helper' class which is not available outside the class in which you define it. To do that, you must define your helper class in the same .as file, but outside the package. I don't usually recommend this, as it's more difficult than standard classes for not much gain. |
|
|
|
|
|
#3 |
|
Ө_ө sleepy mod
Join Date: Mar 2003
Location: Oregon, USA
Posts: 2,350
|
You'd need to write a custom class with those properties declared as public variables (or getter/setter pairs). Aside from giving you typing information in the compiler, this will also let your code run a little faster (since it doesn't need to infer the types at runtime).
__________________
Please use [php] or [code] tags, and mark your threads resolved 8) |
|
|
|
![]() |
| Tags |
| object, property, strict, type |
|
||||||
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|