MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manuel d'utilisateur Page 16

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 184
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 15
16 Getting Started
Step 4: Update events
The Event model changed in Flex 2. However, you can migrate most event handlers with
minimal effort. This section describes the most popular changes that you must make to your
event handling code. For more information about migrating events, see Chapter 6, “Events,
on page 111.
Specify types
Events are now more strongly typed than in Flex 1.x. As a result, you should specify the object
type in the event listener function. For example, previously you could write the following:
function myListener(event) { var s = event.type; }
Now, you must specify an event object in the functions signature; for example:
private function myListener(event:Event):void { var s = event.type; }
Where possible, make the events as specific as possible. If the previous example was a listener
for click events, specify a MouseEvent as the type:
private function myListener(event:MouseEvent):void { ... }
Dispatch custom events
When you dispatch custom events, you must declare a new Event object rather than use a
generic object; for example:
click="dispatchEvent(new Event('checkOut'))"
Remove delegates
You are no longer required to wrap a listener function with a Delegate to maintain application
scope. You can remove the Delegate from the following line:
b1.addEventListener("click", mx.utils.Delegate.create(this,myListener));
So the line appears as follows:
b1.addEventListener(MouseEvent.CLICK, myListener);
Vue de la page 15
1 2 ... 11 12 13 14 15 16 17 18 19 20 21 ... 183 184

Commentaires sur ces manuels

Pas de commentaire