Nella documentazione presente sul sito trovi degli esempi che possono aiutarti a capire meglio
callback function to be called when finished (function or object with scope, func and args or string)
function as callback
function onEnd(){
trace("onEnd");
}
my_mc.tween("_x",100,1,"linear",0,onEnd);
// scope of function is my_mc._parent
object as callback
You can pass as callback object with properties
func - function to be called when tween is finished
scope - scope of function (this in called function)
args - array of arguments passed to function
updfunc - reference to function to be called on every update
updscope - scope of update function (this object)
updargs - array of arguments passed to update function
startfunc - reference to function to be called on start of tween
startscope - scope of start function (this object)
startargs - array of arguments passed to start function
* internal mechanism is: func.apply(scope,args)
// on _root
game={};
game.players = ["john","steve"];
game.showScore = function(id, score){
trace("(this==_root.game) is "+(this==_root.game));
trace(this.players[id] + " has " + score + " points");
}
// somewhere in nested movieclip
var callback = {scope: _root.game, func: _root.game.showScore, args:[1,39]};
my_mc.tween("_x",100,1,"linear",0,callback);
/* or in 1 line:
my_mc.tween("_x",100,1,"linear",0,{scope: _root.game, func: _root.game.showScore, args:[1,39]});
*/
//output after finishing tween:
(this==_root.game) is true
steve has 39 points
string as callback
callbacks can be too defined as strings
my_mc.tween("_x",100,1,"linear",0,'_root.gotoAndPl ay(8)');
it is very problematic determine type of primitive parameters(number, string, boolean), in this case is 8 string
for save type of passed argument use references:
function callMe(my_obj, my_nr, my_bool) {
trace(my_obj +">> typeof(my_obj) is "+ typeof(my_obj));
trace(my_nr +">> typeof(my_nr) is "+ typeof(my_nr));
trace(my_bool +">> typeof(my_bool) is "+ typeof(my_bool));
}
test_obj = {name: "test", id: 10};
test_bool = true;
test_nr = 99;
my_mc.tween("_x",100,1,"linear",0,'_root.callMe(te st_obj,test_nr,test_bool)');
Do not add spaces between argumets
Lo scope come puoi vedere dagli esempi è praticamente l'oggetto che contiene la funzione (come puoi vedere ad esempio nella parte di esempio
game={};
game.players = ["john","steve"];
game.showScore = function(id, score){
trace("(this==_root.game) is "+(this==_root.game));
trace(this.players[id] + " has " + score + " points");
}
// somewhere in nested movieclip
var callback = {scope: _root.game[...]
La funzione "showScore" è contenuta nell'oggetto "game", e quindi come scope tu indichi il percorso di tale oggetto, che è appunto "_root.game" (in quanto si trova sulla timeline principale)


Rispondi quotando