Been an actionscript developer for about 13 years now, have watched the language
grow from a pseudo-scripting language (Flash 4) to an OOP scripting language
(AS1 in Flash 5) to a compile-time typed language (AS2 in w. Flash MX 2004, also
when Macromedia Flex 1 came out), to a proper strongly-typed language with AS3
in 2005, which is when Adobe Flex 2 came out. Moock's "Essential ActionScript
3.0" by O'Reilly was like, The Bible. (Those were the days, eh? :) Still is,
actually. So if you don't have a copy, GET ONE. AND READ IT COVER TO COVER. Do
that and you will "get" AS3 like no one else.

Had a smattering of other lang xp back in high school, did some C#, Pascal and
assembly back in the day. Went to art school, became an artist, then a graphic
designer, then a "web designer" (GOD I hated JavaScript and the netscape vs IE
browser wars -- the names change but the browser wars remain, eh?), then a
"deseloper" when I discovered Flash in 1999, then got back into programming
fulltime around 2003, never looked back since. Piddled around with Java, C, PHP
since then. But enough about me.

>From what I can remember of my basic AS3, typing goes like this:

Declared Type:
var someVar:String = "blah";

Unassigned Type:
var someVar:* = returnedFromService;
(You might want to do this when you're unsure what type you'll get back so that
your code does not throw a runtime error. Use it sparingly, or you'll have a
hard time tracking down bugs... oh gee! Just like JavaScript! ;) )

Untyped:
var someVar = "blah";
(Note this will generate a warning in normal compiler mode, but an error in
strict mode)

Explicit Type Conversion/Casting:
var quantity:int = int(quantityString);

Implicit Type Conversion:
var quantityString:String = "the text is" + quantity;

Type Checking (is operator):
var mySprite:Sprite = new Sprite();
trace(mySprite is Sprite); // true

Type Checking returning an expression (as operator):
var mySprite:Sprite = new Sprite();
trace(mySprite as Sprite); // [object Sprite]

Using explicit casting vs "as" operator:
var thisClip:MovieClip = MovieClip(myMC); // throws an error when it fails
var thisClip:MovieClip = myMC as MovieClip; // returns null when it fails

So depending on the circumstances, whether you want something to return a
runtime error or fail silently, you might want to use either explicit casting or
the "as" operator.

_______________________________________________________________________

Joseph Balderson, Flex & Flash Platform Developer :: http://joeflash.ca
Author, Professional Flex 3 :: http://tinyurl.com/proflex3book

Scott Matheson wrote:
> Hi
>      I have been hacking code for 30 years, I started with PL1 and moved on, 
> I have been hacking
> Flex for the past 3 years getting along nicely, before Flex I never worked 
> with an object based language
> 
> My son 28 codes with me, for the past 2 years we have work on different areas 
> of the same app
> 
> So my New Years resolution is to understand the AS as I never use AS (type 
> casting) , Chris makes use of the AS all the time, does anyone want to help 
> me understand AS and make my resolution, or am I too old :(
> 
> Scott
> 
> 
> 
> 
> Sent from my iPad
> 
> ________________________________
> 
> Disclaimer: This electronic mail and any attachments are confidential and may 
> be privileged. If you are not the intended recipient, please notify the 
> sender immediately by replying to this email, and destroy all copies of this 
> email and any attachments. Thank you.
> 

Reply via email to