Skip navigation
Currently Being Moderated

Using dispatchEvent to communicate between swc and main app...

Apr 12, 2012 12:35 PM



I'm trying to get my custom .swc to communicate with my main application via the use eventDispatchers and listeners.


In my main app I have this:





            public function CustomList():void {


                this.addEventListener(Event.INIT, onInit);



            public function onInit(e:Event):void {

                this.addEventListener("hello", onHello);



            public function onHello(event:Event):void {

                trace("oh hello");





<views:MySkinnableContainer id="mySkinnableContainer" skinClass="skins.MySkinnableContainerSkin"/>


<s:HGroup verticalAlign="bottom" width="100%" horizontalAlign="center" paddingRight="70" paddingBottom="30" paddingTop="500">

        <s:Button id="submitBtn" buttonMode="true" click="CustomList(event)" enabled="true"/>





Within my skinnable container, I have this code attached to a button that the user clicks:


public function onSubFormFinishClick(event:MouseEvent):void


            trace("dispatching event: hello");

            dispatchEvent(new Event("hello", true, true));



However, I'm confused on how to initiate the listening of the dispatchedEvent. I have it currently attached to a button in my main app, but this does not seem to be working. I'm a bit thrown off based on the paradigm difference between Flash and Flex. Could anyone help straighten me out and explain why things aren't wired up correctly, or make this code work efficiently?


Thanks so much for any help, I'm struggling to get myself rooted in Flex.


  • Currently Being Moderated
    Apr 13, 2012 2:18 AM   in reply to Chipleh

    In the skinnable container button click dispatch event as below:


    FlexGlobals.topLevelApplication.dispatchEvent(new Event("hello", true, true));


    And in main application onCreationComplete() event register event handler as :


    FlexGlobals.topLevelApplication.addEventListener("hello", onHello);

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points