I'm developing a custom component called 'DisplayPod' that is supposed to build its internal controls based on an event.
Once the application's 'front controller' parses external application data into different categories, it notifies all instances of the DisplayPod custom component through event dispatching. The custom event type that is dispatched, called DisplayPodEvent, has different names; each name correlates to one of the parsed categories. If an instance-level property in the DisplayPod matches the event name, the component will build itself accordingly (the component's child-level controls are determined by the associated category so it is designed to build its controls for any of the categories it has been pre-set to dipslay). The problem is that the DisplayPod is not responding to the event dispatch, even though it is clearly listening for that event. When I debug the app, I get the following output: ------------------------------------------------------------ [SWF] C:\...\Flex Builder 3\MyAccountFlexDemo\bin-debug\MyAccountFlexDemo.swf - 1,271,036 bytes after decompression The displayProfile Display Pod is listenting. The displayAccessInfo Display Pod is listenting. The displayContactInfo Display Pod is listenting. Dispatching... All 5 DisplayPodEvents have been dispatched. ------------------------------------------------------------ The DisplayPod instances have been preset with their own names to match the available DisplayPodEvents... The DisplayPod instances have successfully attached the appropriate event listener function (via 'addEventListener()' )... The FrontController has dispatched all of the versions of the DisplayPodEvent as required... Additionally, I've registered the DisplayPod custom component with each of the DisplayPodEvent names through a metadata tag. With all these factors considered, I don't understand why the DisplayPod's listener function isn't triggered after the FrontController does its event dispatch. Can you help me figure why this isn't happening as it should and how to trigger the listener function? Thanks. I've included a code sample in this thread and I've placed the entire app here: http://www.futurewebstudios.com/flex_src.zip Here's the code where the dispatch is taking place; this should REPLACE the file of the same name in the zip file as it is more current: package controller { import flash.events.Event; import flash.events.EventDispatcher; import flash.net.URLLoader; import flash.net.URLLoaderDataFormat; import flash.net.URLRequest; import mx.core.Application; import mx.events.FlexEvent; import model.ApplicationDataModel; import model.data.User; import events.DisplayPodEvent; /* The FrontController class is the centralized location for event handling in the application. */ public class FrontController extends EventDispatcher { /* Class-level properties */ public static const XML_DATA_SOURCE:String = "model/database/xml/"; /* Instance-level properties */ private var _app:MyAccountFlexDemo = Application.application as MyAccountFlexDemo; [Bindable] private var _dataModel:ApplicationDataModel = ApplicationDataModel.getInstance(); /* Class constructor */ public function FrontController():void { _app.addEventListener( FlexEvent.CREATION_COMPLETE, onCreationComplete ); } /* Instance-level methods */ private function onCreationComplete( e:FlexEvent ):void { var usersXmlLoader:URLLoader = new URLLoader(); usersXmlLoader.dataFormat = URLLoaderDataFormat.TEXT; usersXmlLoader.addEventListener( Event.COMPLETE, onUsersXMLLoadComplete ); usersXmlLoader.load( new URLRequest( XML_DATA_SOURCE + "users.xml" ) ); var accessInfoXmlLoader:URLLoader = new URLLoader(); accessInfoXmlLoader.dataFormat = URLLoaderDataFormat.TEXT; accessInfoXmlLoader.addEventListener( Event.COMPLETE, onAccessInfoXMLLoadComplete ); accessInfoXmlLoader.load( new URLRequest( XML_DATA_SOURCE + "dpAccessInfoForm.xml" ) ); var contactInfoXmlLoader:URLLoader = new URLLoader(); contactInfoXmlLoader.dataFormat = URLLoaderDataFormat.TEXT; contactInfoXmlLoader.addEventListener( Event.COMPLETE, onContactInfoXMLLoadComplete ); contactInfoXmlLoader.load( new URLRequest( XML_DATA_SOURCE + "dpContactInfoForm.xml" ) ); var passwordEditXmlLoader:URLLoader = new URLLoader(); passwordEditXmlLoader.dataFormat = URLLoaderDataFormat.TEXT; passwordEditXmlLoader.addEventListener( Event.COMPLETE, onPasswordEditXMLLoadComplete ); passwordEditXmlLoader.load( new URLRequest( XML_DATA_SOURCE + "dpPasswordEditForm.xml" ) ); var profileXmlLoader:URLLoader = new URLLoader(); profileXmlLoader.dataFormat = URLLoaderDataFormat.TEXT; profileXmlLoader.addEventListener( Event.COMPLETE, onProfileXMLLoadComplete ); profileXmlLoader.load( new URLRequest( XML_DATA_SOURCE + "dpProfileForm.xml" ) ); var subscriptionReportXmlLoader:URLLoader = new URLLoader(); subscriptionReportXmlLoader.dataFormat = URLLoaderDataFormat.TEXT; subscriptionReportXmlLoader.addEventListener( Event.COMPLETE, onSubscriptionReportXMLLoadComplete ); subscriptionReportXmlLoader.load( new URLRequest( XML_DATA_SOURCE + "dpSubscriptionReportForm.xml" ) ); } private function onUsersXMLLoadComplete( e:Event ):void { _dataModel.usersList = XMLList( e.target.data ); /* Select individual user from users list;; to be determined randomly at later date */ setCurrentUser( _dataModel.usersList.user[ 0 ] ); } private function onAccessInfoXMLLoadComplete( e:Event ):void { _dataModel.displayPodForms["AccessInfo"] = XMLList( e.target.data ); } private function onContactInfoXMLLoadComplete( e:Event ):void { _dataModel.displayPodForms["ContactInfo"] = XMLList( e.target.data ); } private function onPasswordEditXMLLoadComplete( e:Event ):void { _dataModel.displayPodForms["PasswordEdit"] = XMLList( e.target.data ); } private function onProfileXMLLoadComplete( e:Event ):void { _dataModel.displayPodForms["Profile"] = XMLList( e.target.data ); } private function onSubscriptionReportXMLLoadComplete( e:Event ):void { _dataModel.displayPodForms["SubscriptionReport"] = XMLList( e.target.data ); } private function setCurrentUser( item:XML ):void { _dataModel.currentUser.userId = item.userid; _dataModel.currentUser.password = item.password; _dataModel.currentUser.occupation = item.occupation; _dataModel.currentUser.industry = item.industry; _dataModel.currentUser.firm = item.firm; _dataModel.currentUser.subscribeDate = item.subscribedate; _dataModel.currentUser.firstName = item.firstname; _dataModel.currentUser.lastName =item.lastname; _dataModel.currentUser.address1 = item.address1; _dataModel.currentUser.address2 = item.address2; _dataModel.currentUser.city = item.city; _dataModel.currentUser.region = item.region; _dataModel.currentUser.countryCode = item.countrycode; _dataModel.currentUser.postalCode = item.postalcode; _dataModel.currentUser.phone = item.phone; _dataModel.currentUser.fax = item.fax; _dataModel.currentUser.email = item.email; _dataModel.currentUser.yearsOfPractice = item.yearsofpractice; _dataModel.currentUser.jobTitle = item.jobtitle; var subscriptions:Array = new Array(); var node:XML; for each ( node in item.subscriptions ) { for each ( node in node.subscription ) { subscriptions.push( String( node.children() ) ); } } _dataModel.currentUser.subscriptions = subscriptions; /* Now that currentUser is available, separate user's data for display on various pages of application */ getUserDataForDisplayPods( _dataModel.currentUser ); } private function getUserDataForDisplayPods( u:User ):void { /* Establish AccountDataGroups from selected user's properies */ var adp:AccountDataParser = new AccountDataParser( u ); _dataModel.userProfile = adp.createAccountDataGroup( AccountDataParser.PROFILE ); _dataModel.userAccessInfo = adp.createAccountDataGroup( AccountDataParser.ACCESS_INFO ); _dataModel.userContactInfo = adp.createAccountDataGroup( AccountDataParser.CONTACT_INFO ); _dataModel.userPasswordEdit = adp.createAccountDataGroup( AccountDataParser.PASSWORD_EDIT ); _dataModel.userSubscriptionReport = adp.createAccountDataGroup( AccountDataParser.SUBSCRIPTION_REPORT ); /* Send the established AccountDataGroups to their respective DisplayPods */ trace( "Dispatching..." ); _app.dispatchEvent( new DisplayPodEvent( _dataModel.userProfile, DisplayPodEvent.DISPLAY_PROFILE ) ); _app.dispatchEvent( new DisplayPodEvent( _dataModel.userAccessInfo, DisplayPodEvent.DISPLAY_ACCESS_INFO ) ); _app.dispatchEvent( new DisplayPodEvent( _dataModel.userContactInfo, DisplayPodEvent.DISPLAY_CONTACT_INFO ) ); _app.dispatchEvent( new DisplayPodEvent( _dataModel.userPasswordEdit, DisplayPodEvent.DISPLAY_PASSWORD_EDIT) ); _app.dispatchEvent( new DisplayPodEvent( _dataModel.userSubscriptionReport, DisplayPodEvent.DISPLAY_SUBSCRIPTION_REPORT ) ); trace( "All 5 DisplayPodEvents have been dispatched." ); } } }