To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-08-2010, 06:02 PM   #1
badaboom55
Senior Member
 
Join Date: Jan 2006
Posts: 100
Question Should/Can I strict type a custom Object's properties?

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:
myObject = new Object();
myObject.nameLabel = "New Releases";
myObject.artOrientation = "portrait";
myObject.artAmount = 5;
I find the new compiler and debugger capabilities very helpful, since I'm not the most detail-oriented, so I (usually) like that Flash forces me to strict-type my variables and such.

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!
badaboom55 is offline   Reply With Quote
Old 02-08-2010, 06:07 PM   #2
5TonsOfFlax
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.
5TonsOfFlax is offline   Reply With Quote
Old 02-08-2010, 06:10 PM   #3
neznein9
Ө_ө 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)
neznein9 is offline   Reply With Quote
Reply

Tags
object, property, strict, type

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:30 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.