-
What is with the colons!?! Flash 8 AS Theory
Hey all,
I thought using colons in code was old school Actionscript, and had been deprecated, but since Ive been using Flash 8 ive seen it popping up in AS examples everywhere.
Examples below.
var myCT:ColorTransform = new ColorTransform();
var mc:MovieClip = scope.createEmptyMovieClip("mc_" + depth, depth);
var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);
I have bolded the colons in question.
Why are they there??
For instance, couldnt we replace
var myCT:ColorTransform = new ColorTransform();
with
var myCT = new ColorTransform();
I tried it, and it works, why use the colons at all? is it better OOP convention??
Cheerz,
Dwayne
-
It's to specify what myCT actually is. Actionscript is kind of a lax, stupid language when it comes to variable types. If you do var myNum = 4, then it will automatically cast myNum as a number, where technically you should do var myNum:Number = 4, so that you're specifying what it should be. It's what you're supposed to do technically, although some people don't.
-
asdf
Ah! i have a question about that-
because you dont state what the variable will be filled with before you fill it, it must take a small extra function to test for What you are filling it with, and then to fill the variable with it. So, therefore, if you state what the variable will be going into it, it saves the flash runner the effort of testing for what your filling it with.
I think. Not sure.
Makes sense to me, but these things rarely work out as a human mind would think sensible.
maximum width 300 no more maximum hieght 40 no more not interchangable
-
I personally think you should always use strict data typing.
Not only is it easier for others to read your code and figure it out, but it protects you from making errors such as assigning a string to what's supposed to be a number(you'll actually be fed that error rather than having to search for it on your own).
-
Ok, so the general consensus is, USE THE COLONS
Guess i better bow to community pressure!
Cheerz,
Dwayne
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|