General coding questions

I’m a noob when it comes to coding, and I’m wondering if there’s a book or online resource that I can look at for a general coding guide, because everything I know comes from either this site or from some javaScript, asp, and htmlDOM tutorials.

Some specific questions, specifically referencing Kirupa’s Animating Dynamic MovieClips in CS3:

-When do I need to label a function’s output as void? such as:
function Main() or function ZoomCircle(e:Event):void

-I’m thinking that circleMC:MovieClip is adding circleMC to the MovieClip class, but I’m not sure what the e.target accomplishes. e seems to come up a lot, followed by a “.” or a “:” but I don’t know why it needs a “.” versus a “:”
var circleMC:MovieClip = MovieClip (e.target);
[slight change to the question. I’m thinking that “e” is a local variable, but I still don’t understand e.target]

anyways, thanks for the help.

-When do I need to label a function’s output as void? such as:
function Main() or function ZoomCircle(e:Event):void

You never need to give a function a return type unless you’re overriding an older method. However, it is considered best practice to type functions, and void is used to indicate that no value is ever returned from the function. That means that you either use the return statement somewhere in your function with no value after it, or you never use the return statement at all.

-I’m thinking that circleMC:MovieClip is adding circleMC to the MovieClip class, but I’m not sure what the e.target accomplishes. e seems to come up a lot, followed by a “.” or a “:” but I don’t know why it needs a “.” versus a “:”
var circleMC:MovieClip = MovieClip (e.target);

In this context, the colon use is part of ActionScript’s postcolon syntax for declaring the type of a variable. circleMC isn’t really being added to the MovieClip class, but the compiler is being told what to expect from that variable in terms of which methods it has and where it should be used.

e is usually the name of the parameter of a function that’s being used as a handler as part of AS3’s event system. It stores information relevant to the event that has just occurred. The Event class’s target property is described pretty well in the documentation: The event target. This property contains the target node. For example, if a user clicks an OK button, the target node is the display list node containing that button.

The dot accesses object properties.

thanks for the description.

as for e, are you saying that it is just common practice to use that when dealing with an event? I was looking at some other tutorials, and they were using evt in that spot.

as for the different properties, methods, and parameters, is there a list somewhere online that just has a list of different options, and which classes they apply too?

It’s just a variable name. e is nice and short, and a good convention, but it could be almost anything. If you like calling your events monkeyToes that’d work too.


function onMouseClick(monkeyToes:MouseEvent):void
{
     trace("I should have used 'e'!");
}

Personally, I tend to not use just the letter “e” for event returns (using “evt” instead as “event” is a reserved word) - single letter variables are best left as loop iterators (counters) :slight_smile:

I’d recommend you grab a copy of Essential ActionScript 3.0 by Colin Moock, pub. O’Reilly. Lots of good information in there.

It’s really a personal choice. As far as I’m concerned, there’s no good reason to type more than a single character, and e does the trick nicely. evt is fine too, but really, why make it longer? There are still 25 other letters if you need loop iterators.

[QUOTE=aforeigner;2352633]
-When do I need to label a function’s output as void? such as:
function Main() or function ZoomCircle(e:Event):void
[/QUOTE]

It’s general practice (expecially when writing classes) that you type functions. A Type void indicates there is no returned type from the function.

[QUOTE=aforeigner;2352633]
-I’m thinking that circleMC:MovieClip is adding circleMC to the MovieClip class, but I’m not sure what the e.target accomplishes. e seems to come up a lot, followed by a “.” or a “:” but I don’t know why it needs a “.” versus a ":"
var circleMC:MovieClip = MovieClip (e.target);
[/QUOTE]

(e) is a general parameter name when constructing functions as for event listeners, eg.

foo.addEventListener(SomeEvent.Type, myFunction)

function myFunction(e:SomeEvent):void
{
  e.target
}

Well… there is the language reference: http://livedocs.adobe.com/flex/3/langref/index.html

…and something is probably wrong in your code if you are running out of letters for nested iterators. :stuck_out_tongue: