One of the strengths of Adobe Flash lies in the choice of the ECMAScript (ECMA-products - E uropean C omputer A ssociation anufacturers M) as the standard scripting. ActionScript and JavaScript, in fact, both stem from a higher standard as they are extremely similar. This is one of the reasons for which many ActionScript programmers develop very easily in JavaScript and vice versa.
ActionScript has always had a management "double" of events that often has confused some developers. In MovieClip, for example, you can set an event by simply declaring a function to the properties of the event, for example:
Method 1
1 2 3 | ( ) { mio_mc. onRelease = function () { "Click sul MovieClip" ) ; trace ("Click on the MovieClip"); } |
Other objects, in contrast, require a different handling of the event that you want to monitor, requiring the classical listener, an object designed for this task. For example, the Mouse object can be controlled in this way:
Method 2
1 2 3 4 5 |
The components have a further variant, as the Loader component:
Method 3
1 2 3 4 5 | Object = new Object ( ) ; loaderListener var: Object = new Object (); = function ( evt : Object ) { loaderListener. complete = function (evt: Object ) { "Caricamento completato" ) ; trace ("Upload completed"); }; ( "complete" , loaderListener ) ; myLoader_ldr. addEventListener ("complete", loaderListener); |
Why these differences? The reason, indeed, is very simple. Method 1, the most immediate, is used when the event to "intercept" is unique, that is when it makes no sense to "take" several functions one after all ' other. Methods 2 and 3, however, create the "lists" of "listeners" and are extremely useful and powerful because they allow you to attach virtually infinite number of functions to a particular event.
The same thing happens in JavaScript and can be seen in libraries as a prototype . The convenient observe () method, available from the event, allows you to fit a function to an event object. For example:
1 | window , 'load' , function ( ) { alert ( "Finestra caricata" ) ; } ) ; Event. Observe (window, 'load', function () {alert ("Window loaded");}); |
In this case we have attached our function that displays an alert to the load event of the window object. We could only repeat the statement and attach additional event:
1 2 | window , 'load' , function ( ) { alert ( "Finestra caricata - 1" ) ; } ) ; Event. Observe (window, 'load', function () {alert ("Window loaded - 1");}); window , 'load' , function ( ) { alert ( "Finestra caricata - 2" ) ; } ) ; Event. Observe (window, 'load', function () {alert ("Window loaded - 2");}); |
This feature, also common in ActionScript, it is extremely versatile, especially in JavaScript, is the key to the creation of many "widgets" and extensions (see the classic snap ) now proliferating on the Web The ability to tag along, in fact , for events that are already controlled by other functions, can be non-intrusive (Unobtrusive) and then, in practice, to add functions to those already present.







Latest Comments
Giovambattista Fazioli : @ paso: absolutely. Simply identifying the field [cci] input [/ cci] you want to ...
paso : Hello I would like to request a service, you can use the datepicker with cform7 I spiegp best I can implement ...
Simon : It annoys disturbed again and use that space for these things ... however it does not work ...
Giovambattista Fazioli : @ Barbara: If you mean the bottom to start writing down what it depends on where ...
Barbara : Hello, is very interesting but how do you write at the bottom instead of the above? Thanks