Adobe Flex PopupManager.centerPopup timing bug workaround
So I had timing bug when working on a project, where I wanted to launch a PopupManage popup to allow the user to change their password if a flashvar was set. The flashvar would be set in response to a link click from the user’s email.
The problem is that no matter what I tried I couldn’t get my popup to center if it was called from an event fired in the Application.applicationCompelete event handler. Basically, I have PopupManager.centerPopUp(this) in the creation complete event handler of the Popup up component, but for whatever reasons, the Application’s screen height and width were still set at zero at this stage, presumably because the screen hadn’t been drawn yet. I tried adding a callLater around the centerPopup call, but that didn’t work.
The fix was to put the callLater around the initial dispatchEvent call in the applicationComplete handler. This provided enough of a delay for the screen to be set properly.
if(parameters['password_reset_code'] && parameters['password_reset_code'] != '') {
callLater(function():void {
var pw_reset_evt:GenericEvent = new GenericEvent("PASSWORD_RESET_CODE", parameters['password_reset_code']);
dispatchEvent(pw_reset_evt);
});
}
There really should be a ‘callIn’ method as well as the ‘callLater’ method. callIn would take a time in seconds or milliseconds to delay before calling the code, and would wrap the whole dynamic Timer object handling.
GenericEvent is just an Event wrapper with a ‘data’ field.
package com.vitrue.shared.events {
import flash.events.Event;
public class GenericEvent extends Event {
public static var EVENT_PREFIX:String = "GenericEvent";
public var eventType:String;
public var data:*;
public function GenericEvent(type:String, data:Object) {
eventType = type;
super(EVENT_PREFIX + type);
this.data = data;
}
public static function EVENT(type:String):String {
return EVENT_PREFIX + type;
}
}
} Trackbacks
Use the following link to trackback from your own site:
http://blog.slaingod.com/trackbacks?article_id=adobe-flex-popupmanager-centerpopup-timing-bug-workaround&day=21&month=07&year=2009