我正在与Flex一起使用Swiz框架。我正在尝试使用mediate标记,这是我的问题:
public class Locale {
private static function onLoadSuccess(event:Event):void
{
// I have a break point here. I can tell that this code is being executed sucessfully
Swiz.dispatchEvent(new DynamicEvent(ConfigConstants.LOCALE_RESOURSE_LOADED));
}
}在另一个类中,这里有这样的代码:
public class AcordianPane {
...
[Mediate( event="localeResourseLoaded")]
public function onLocaleResourseLoaded( ...rest):void
{
this.label = Locale.getUiString("title.map.broadcast");
}
...
}上面的代码按预期工作。当我将Mediate标记更改为常量时,我遇到了一个问题:
public class AcordianPane {
...
[Mediate( event=ConfigConstants.LOCALE_RESOURSE_LOADED)]
public function onLocaleResourseLoaded( ...rest):void
{
// THIS IS NOT EXECUTED NOW!
this.label = Locale.getUiString("title.map.broadcast");
}
...
}有人知道为什么会这样吗?作为参考,这是我的ConfigConstants类:
public class ConfigConstants {
public static const LOCALE_RESOURSE_LOADED:String = "localeResourseLoaded";
}注意: Mediate标记与EventListener标记相同,名称在几个关联之前刚刚更改。我知道它现在已经贬值了,但我不认为有任何理由在我们的代码基础上进行查找和替换。
编辑1:我刚刚尝试用Mediate替换EventHandler,但也出现了同样的问题。
编辑2:这是Swiz网页上的相关文件。
编辑3:我也尝试过用引文(谢谢@Gerhard' s )来引用这个事件:
[EventHandler( event="ConfigConstants.LOCALE_RESOURSE_LOADED")]
public function onLocaleResourseLoaded( ...rest):void
{
this.label = Locale.getUiString("title.map.broadcast");
}但这一事件仍未收到。我认为问题可能在于我初始化Swiz的主要mxml文件:
<swiz:SwizConfig
strict="true" // set by a co-worker
mediateBubbledEvents="true" // set by a co-worker
viewPackages="com.sixtyfootersdude.views" // set by a co-worker
eventPackages="com.sixtyfootersdude.model" // <-- Just added!
beanLoaders="{ [ com.sixtyfootersdude.admin.AdminBeans ] }" /> // set by a co-worker还请注意
AcordianPane在com.sixtyfootersdude.viewsLocale在com.foxtrot.utilConfigConstants在com.sixtyfootersdude.model编辑4:我尝试的最后一件事是:
[EventHandler( event="com.sixtyfootersdude.model.ConfigConstants.LOCALE_RESOURSE_LOADED")]
public function onLocaleResourseLoaded( ...rest):void{
this.label = Locale.getUiString("title.map.broadcast");
}和
<swiz:SwizConfig
strict="true"
mediateBubbledEvents="true"
viewPackages="com.sixtyfootersdude.views"
beanLoaders="{ [ com.sixtyfootersdude.admin.AdminBeans ] }" />发布于 2011-09-19 18:57:24
在元标记中不能使用常量。不幸的是,这是Flex的限制。相反,您必须使用常量的名称作为字符串。但是,Swiz将在初始化时检查这些常量是否存在。因此,如果您配置错了[EventHandler],您将在应用程序启动期间得到一个错误。
因此,在您的例子中,解决方案如下所示:
[EventHandler(event = "ConfigConstants.LOCALE_RESOURSE_LOADED")]
public function onLocaleResourseLoaded():void
{
}确保ConfigConstants包在您的SwizConfig中配置为eventPackage。
要获得更多信息,请查看使用类名和常量名称处理事件和Swiz配置。
顺便说一句:你不应该再使用不推荐的[Mediate]了。
https://stackoverflow.com/questions/7475311
复制相似问题