Actionscript 2 Proper way to define function on MovieClip -
i'm trying write function on movieclip, , call root clip. works fine in actionscript 3 doesn't seem working in actionscript 2.
frame 1 of _root
movieclip:
var newmovieclip:movieclip = _root.attachmovie('notification', id, 0); newmovieclip.setnotificationtext("test text");
frame 1 of notification
movieclip:
function setnotificationtext(inputtext : string){ notificationtext.text = inputtext; }
the result movieclip created text not changed.
am doing wrong?
to add functions movieclip in as2, need use 1 of these methods:
add method prototype of movieclip:
movieclip.prototype.setnotificationtext = function(inputtext:string):void { if(this["notificationtext"] !== undefined) { // if we're going use prototype, @ least checks // make sure caller movieclip has text field expect. this.notificationtext.text = inputtext; } } newmovieclip.setnotificationtext("test text");
make movieclip , argument of function:
function setnotificationtext(mc:movieclip, inputtext:string):void { mc.notificationtext.text = inputtext; } setnotificationtext(newmovieclip, "test text");
add method directly newly created movieclip:
var newmovieclip:movieclip = _root.attachmovie('notification', id, 0); newmovieclip.setnotificationtext(inputtext:string):void { notificationtext.text = inputtext; } newmovieclip.setnotificationtext("test text");
option 2 best overall - it's cleanest , avoids overhead of creating new function every new movieclip. avoids messing around prototype, @ best should used add generic methods, removeitem()
method on array
.
Comments
Post a Comment