![Flex Alert的匿名回调函数如何得到正确的this Flex Alert的匿名回调函数如何得到正确的this](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Flex中经常使用Alert来弹出提示或确认窗口,为了方便省事,会直接用匿名函数作为回调,但有时如果要调用外部的this,你会发现匿名函数中的this无法指向外部父类,可以使用e.target获取parent,当然这个parent是Alert.show的另一个参数所指定,正确写法如下:
Alert.show("您的密码已过期,请及时修改登录密码!", "提示", Alert.OK|Alert.CANCEL, this, function(e:CloseEvent):void
{
if(Alert.OK==e.detail)
{
//弹出修改密码窗口
var form:FormModifyPassword = new FormModifyPassword();
PopUpManager.addPopUp(form, e.target as DisplayObject, true);//在此处使用this将报错
PopUpManager.centerPopUp(form);
}
});