views:

528

answers:

2

I see $(var) often in the Actionscript code I am looking through, where var is a variable that is previously defined. What does it mean exactly?

+1  A: 

It's a function called $, jQuery actually uses it a lot

Sander Rijken
+1  A: 

EDIT: Thanks to joshtynjalas correction, the following line is wrong, sorry! The dollar sign can actually be used exactly the same way as in JS (see example at the bottom):

In Actionscript you cannot use the $ sign on its own as a property name (at least in AS2 and AS3).

It is possible to use it in combination with other characters though. It happens that developers uses it as prefix to identify static fields or constants (e.g. private static var $boxHeight:int = 480 ).

FYI, here's a word from the ECMA Script specifications :

"This standard specifies one departure from the grammar given in the Unicode standard: The dollar sign ($) and the underscore (_) are permitted anywhere in an identifier. The dollar sign is intended for use only in mechanically generated code."

I guess you mixed it up with Javascript where the dollar sign can be considered as a variable name. Thanks to that you can assign it as a shortcut reference to a predefined function.

function popup(value)
{
   alert(value)
}

$ = popup;

$("hello");
$("world");

The practice was widely introduced by Prototype(.js) in order to abstract the quite painful getElementById(id_name);

Theo.T
The following code works fine in AS3 var $:String = "hi";trace($); You can also name functions with only the $ character, just like JavaScript. That's part of the ECMAScript spec, and Adobe's implementation does not differ in this regard.
joshtynjala