flash language_api_execution_context
Execution context
To avoid getting a nasty surprise it is worth spending a few moments on the new behaviour of reference functions.
As you probably remember, in ActionScript 1 and 2 we could pass a function in a reference, which then lost its original context and took on the new object as a context:
var person:Object = { age : 25, name : "Bobby" }; // the function to talk is passed as a reference person.to talk = to talk; function to talk ( ) { trace(“hello, my name is “ + this.name + “, I am “ + this.age + “ years oldâ€); } // call the method // display: hello, my name is Bobby, I am 25 years old person.to talk();
In ActionScript 3, the to talk function conserves its original context and doesn’t therefore execute anymore in the person object context:
var person:Object = { age : 25, name : "Bobby" }; // the function to talk is passed as a reference person.to talk = to talk; function to talk ( ) { trace(“hello, my name is “ + this.name + “, I am “ + this.age + “ years oldâ€); } // call the method // display : hello, my name is undefined, I am undefined years old person.to talk();
Many ActionScript developers use this change in context in order to reuse functions.We therefore need to bear in mind this new ActionScript behavior throughout all of these articles.
Mediabox Training Centre © 2000 - 2008 All rights reserved.
Adobe Authorized Training Centre. State convention under number 25 14 02167 14.
Mediabox : SARL au capital de 62.000€ - Activity number: 25 14 02167 14 - SIRET : 493 716 468 00027
MEDIABOX, 102 Avenue des Champs Elysées, 75008 PARIS - Tel. +33(0)2.31.91.96.89 - Fax. +33(0)2.72.68.56.42


