Thanks for the reply and apologies for the late response.

Unfortunately, your second idea may not be practical in my application
as it will only be certain modules listening for these events (what
modules listen to what events would be determined at load time as an XML
configuration file is loaded).

I have tried your other idea, setting the event listener on the module
as it is being dynamically created and then dispatching the event from
the parent, unfortunately that did not seem to work. Code samples below:

RootApplicationFunctions.as(script included on root most application
file so this would be the "parent application")
* NOTE: This function is a couple functions down the chain, originating
from a loop which is iterating over the XML configuration file. It tells
the applications what modules to load. *
private function moduleLoadComplete(event:ModuleEvent):void
{
       // The module itself as a Display Object.
       var visual:DisplayObject = event.module.factory.create() as
DisplayObject;
       // The module container.
       var modContainer:ModuleWrapper = new ModuleWrapper();
       modContainer.id = "module_container" + this._moduleIndex;
       // Add event listeners to the modContainer.
      
modContainer.addEventListener("profileDataUpdated",profileDataUpdatedHan\
dler);
       // Add module to the container.
       modContainer.addChild(visual);
       // Add module container to workspace canvas.
       root_canvas.workspace_canvas.addChild(modContainer);
       this._moduleIndex++;
}

private function sendEvent():void
{
     dispatchEvent(new Event("profileDataUpdated"));
}

I did know if it would be looking for profileDataUpdatedHandler in the
parentApplication or in the moduleWrapper as file itself, so at present
this function exists in both spots:

public function profileDataUpdatedHandler(event:Event):void
{
     Alert.show("module container heard the event: " +
event.target.toString());
}

RootApplication.mxml (this is the file which includes
RootApplicationFunctions.as above)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
                 xmlns:view="view.*"
                 layout="absolute"
                 width="100%"
                 height="100%"
                 creationComplete="rootApplicationInit()">

     <mx:Style source="asset/style/CommunityUI.css" />

     <mx:Script source="RootApplicationFunctions.as" />

     <mx:XML id="OEMConfiguration" source="xml/oemConfiguration.xml" />

     <view:RootCanvas id="root_canvas" />
     <mx:Button click="sendEvent()" />
</mx:Application>


As of yet, I have not been able to get this to work. If I click on the
button on the root, it does fire sendEvent(), but module being loaded is
not responding (technically it is the ModuleWrapper listening, but the
ModuleWrapper passes instructions to the module contained within).

I have other options available to me I suppose, however this is the way
I would like to do it because it seems like the cleanest way.

--- In [email protected], "phipzkillah" <[EMAIL PROTECTED]> wrote:
>
> It's possible.
>
> Main.mxml
> //script
>         private function init():void{
>                      child1.addEventListener("change",
callBackFunction);
>          }
>
>          private function dispatchEventsToChildren():void{
>                      //call this to dispatch an event
>                  dispatchEvent(new Event("change"));
>          }
>
> //or do it this way
>          private function controlChildren(event:ItemClickEvent):void{
>                  child1.publicFunctionUpdateData(args);
>          }
>
>
> //body
> <com:child1 id="child1"/>
> <mx:DateField change="controlChildren(event)"/>
>
>
> Child1.mxml
> Some component you have...
>
>
> --- In [email protected], "brett.hitzel" brett.hitzel@
> wrote:
> >
> > Hi Everyone,
> >
> > I have been charged to architect a fairly large scale Flex
application
> > (first time doing so). I don't think that my issue warrants code
> > samples however if needed I can provide.
> >
> > I have not worked with events too much, but I understand the default
> > three phases it goes through (capture,target,bubble). The
application
> > will be comprised of an application which load a custom MXML
component
> > (basically an extended Canvas), which in turn loads modules based on
> > user interaction. What I need to have happen, is when the root
> > (parentApplication) has values that update, I would like for it to
> > dispatch an event, which the Modules listen for, and then in
response
> > poll the parent for that data to get the new information.
> >
> > Based on everything I have read, events don't propigate in that
> > direction (it climbs down the chain from the top, hits the target,
and
> > then climbs back up). However, is it possible to make it go the
other
> > way? Can children hear events of the parent? If this is impossible,
> > does anyone have any thoughts or suggestions for an alternative to
my
> > particular problem?
> >
> > I appreciate any advice you can offer!
> >
>

Reply via email to