I am using the Swiz framework with Flex. I am trying to use the the mediate
tag with some luck here is my problem:
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));
}
}
In another class I have this code here:
public class AcordianPane {
...
[Mediate( event="localeResourseLoaded")]
public function onLocaleResourseLoaded( ...rest):void
{
this.label = Locale.getUiString("title.map.broadcast");
}
...
}
The code above works as expected. I am experiencing a problem when I change the Mediate
tag to a constant:
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");
}
...
}
Anyone have any idea why this is happening? For reference this is my ConfigConstants class:
public class ConfigConstants {
public static const LOCALE_RESOURSE_LOADED:String = "localeResourseLoaded";
}
Note: The Mediate tag is identical to the EventListener tag the name was just changed several releses ago. I know that it is now depreciated but I don't think there is any reason to do a find and replace on our code base.
Edit 1: I just tried substituting EventHandler
with Mediate
but the same problem occurs.
Edit 2: Here is the relevant documentation from the Swiz webpage.
Edit 3: I have also tried putting the event in quotations (thanks @Gerhard's s) like this:
[EventHandler( event="ConfigConstants.LOCALE_RESOURSE_LOADED")]
public function onLocaleResourseLoaded( ...rest):void
{
this.label = Locale.getUiString("title.map.broadcast");
}
But the event is still not being received. I think that the problem may lie in my main mxml file where I initialize Swiz:
<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
Also note that
AcordianPane
is in com.sixtyfootersdude.views
Locale
is in com.foxtrot.util
ConfigConstants
is in com.sixtyfootersdude.model
Edit 4: The last thing that I tried is this:
[EventHandler( event="com.sixtyfootersdude.model.ConfigConstants.LOCALE_RESOURSE_LOADED")]
public function onLocaleResourseLoaded( ...rest):void{
this.label = Locale.getUiString("title.map.broadcast");
}
And
<swiz:SwizConfig
strict="true"
mediateBubbledEvents="true"
viewPackages="com.sixtyfootersdude.views"
beanLoaders="{ [ com.sixtyfootersdude.admin.AdminBeans ] }" />
You can't use constants in metatags. Unfortunatly that's a restriction of Flex. Instead you have to use the constant's names as strings. However, Swiz will check if those constants exist while it's getting initialized. Therefor you'll get an error during the applications startup if you misconfigured an [EventHandler]
.
So, in your case the solution would look like this:
[EventHandler(event = "ConfigConstants.LOCALE_RESOURSE_LOADED")]
public function onLocaleResourseLoaded():void
{
}
Make sure that the package of ConfigConstants
is configured as eventPackage
in your SwizConfig
.
For more information take a look at Event Handling Using Class and Constant Names and Swiz Configuration.
BTW: You shouldn't use the deprecated [Mediate]
anymore.