Stage:
Stage的更加简单,只是当场景的大小发生变化(场景缩放)的时候获取onResize事件,前提条件是stage.scalemode=”noscale”且不是ShowAll显示。
lsn4 = new Object();
lsn4.onresize = function () {
trace("size changing...");
};
Stage.scaleMode="noscale";
Stage.addListener(lsn4);
TextField:
TextField可以获取的是onChanged和onScroller事件,我们结合昨天的部分程序写一个例子:
Movieclip.prototype.makeBox = function(x, y, l) {
this.lineto(x, y+l);
this.lineto(x+l, y+l);
this.lineto(x+l, y);
this.lineto(x, y);
};
createEmptyMovieClip("scrollUp",3);
with (scrollUp) {
lineStyle(1,0x999999,50);
moveTo(550,200);
beginFill(0x345678,20);
makeBox(550,200,30);
endfill();
}
duplicateMovieClip(scrollUp, "scrolldown", 4);
scrollUp._y-=60;
scrollUp.onPress=function(){txt.scroll--};
scrollDown.onPress=function(){txt.scroll++};
createTextField("txt",5,300,10,100,40);
txt.border=1;
txt.wordwrap=1;
txt.multiline=1;
txt.type="input";
lsn5 = new Object();
lsn5.onScroller = function () {trace("text scrolling") };
lsn5.onChanged = function () {trace("text changed") };
txt.addListener(lsn5);
当文本超过最大长度的时候或者用户按下了scroll按钮的时候并且没有超过最高/最低scroll范围的时候取得onScroller响应;而用户输入文本的时候响应onChanged事件。
FStyleFormat:
FStyleFormat的Listener的作用针对于Components。当用户使用了Components UI或者自定义的Components的时候,如果使用了addListener,那么新的Components的样式就会继承为Listener的样式,例如常用的既是:
globalStyleFormat.background=0x333333;
globalStyleFormat.addListener(ckbox);
场景中存在了一个Components UI的check box的Instance,那么只要使用了addListener之后,那个instance的背景将跟随globalStyleFormat的背景色(自定义的styleFormat也可以)。
今天虽然写到现在已是很晚,但也幸福的有女朋友在旁边陪伴……
源文件:http://www.dnvs.net/tutorial/flash_mx/day7.fla
注:
Listener和Handler
Listener和Handler的区别,从本质即可表达为一个是对象,一个是程序。