Articles Tagged 'Development'


Event management: similarities between Flash and Javascript

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
Object = new Obejct ( ) ; MouseListener var: Object = new Obejct ();
( ) { MouseListener. onMouseMove = function () {
"Mouse in moto" ) ; trace ("Mouse in motion");
}
addListener ( mouseListener ) ; Mouse . addListener (MouseListener);

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.

Continued ...

BlogBabel API beta now

Update: BlogBabel closed - all the services, widgets and plugins are no longer active

With reports of P | xel and Dat I became aware of the new APIs provided by the site BlogBabel . So I released a new version of dell'antipixel BlogBabel Flash.

image

In this new version (who installed the previous version of Flash does not do anything, the update is automatic) are used the new APIs made ​​available by BlogBabel . The code is less invasive and faster than the previous year. From the context menu, also you can access more information and a calculation on the "up" or "down" (green or red background) is now correctly being provided by the same system API BlogBabel .

Remember to use enough to be recorded on the antipixel BlogBabel and insert the following lines of code in your site:

[Html

Latest Comments



Stop SOPA