Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5982535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:06:04+00:00 2026-05-22T22:06:04+00:00

I have a tree, which childs dispaching event, if i run the object outside

  • 0

I have a tree, which childs dispaching event, if i run the object outside TitleWindow – everything is working fine, but if i encapsulate it inside a TitleWindow as into the source below – the event is not anymore dispached system wide.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               xmlns:sparkTree="com.sparkTree.*"
               creationComplete="init()">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.managers.PopUpManager;

            private function init():void
            {
                PopUpManager.addPopUp( xWin, this );
                this.addEventListener( MyEvent.REQUEST_FORWARD, function( e : MyEvent ):void{ Alert.show( ":P" ) } );
            }

        ]]>
    </fx:Script>

    <s:TitleWindow id="xWin" >

        <s:HGroup width="100%" height="100%">
            <sparkTree:Tree labelField="label" 
                    dataProvider="{dataProviderXML}" 
                    width="300" height="500" 
                    textRollOverColor="yellow" 
                    textSelectedColor="0xFFFFFF"
                    itemRenderer="com.sparkTree.XItemRenderer">

                <sparkTree:layout>
                    <s:VerticalLayout gap="0" variableRowHeight="true"/>
                </sparkTree:layout>
            </sparkTree:Tree>
        </s:HGroup>
    </s:TitleWindow>
</s:Application>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:06:05+00:00Added an answer on May 22, 2026 at 10:06 pm

    Change your

    this.addEventListener( MyEvent.REQUEST_FORWARD, function( e : MyEvent ):void{ Alert.show( ":P" ) } );
    

    to

    xWin.addEventListener( MyEvent.REQUEST_FORWARD, function( e : MyEvent ):void{ Alert.show( ":P" ) } );
    

    Or maybe you’re using event bubbling?

    I don’t know details about your code and see it very problematic but this code works fine:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application creationComplete="init()" xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
        <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.managers.PopUpManager;
    
            protected function init():void
            {
                PopUpManager.addPopUp(xWin, this);
                systemManager.addEventListener(MyEvent.REQUEST_FORWARD, function(e:MyEvent):void
                {
                    Alert.show(":P")
                });
            }
        ]]>
        </fx:Script>
        <fx:Declarations>
            <s:TitleWindow id="xWin">
                <s:Button click="xWin.dispatchEvent(new MyEvent(MyEvent.REQUEST_FORWARD))" horizontalCenter="0"
                    verticalCenter="0" />
            </s:TitleWindow>
        </fx:Declarations>
    </s:Application>
    

    Where MyEvent is:

    package
    {
    import flash.events.Event;
    
    public class MyEvent extends Event
    {
        public static const REQUEST_FORWARD:String = "requestForward";
    
        public function MyEvent(type:String)
        {
            super(type, true, false);
        }
    }
    }
    

    But what about me personally I recommend to to change all your code 🙂

    First of all I strongly recommend you to extract your window in a separate component (you should do it all the time and use inline components only for prototyping):

    <?xml version="1.0" encoding="utf-8"?>
    <s:TitleWindow xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx">
        <fx:Metadata>
            [Event(name="requestForward", type="MyEvent")]
        </fx:Metadata>
        <s:Button click="dispatchEvent(new MyEvent(MyEvent.REQUEST_FORWARD))" horizontalCenter="0"
            verticalCenter="0" />
    </s:TitleWindow>
    

    Second, don’t use bubbling events without need especially outside components:

    package
    {
    import flash.events.Event;
    
    public class MyEvent extends Event
    {
        public static const REQUEST_FORWARD:String = "requestForward";
    
        public function MyEvent(type:String)
        {
            super(type);
        }
    }
    }
    

    Third, try not to use inner functions and create separate methods. It is more readable and it is easier to unsubscribe. So our final application:

    <?xml version="1.0" encoding="utf-8"?>
    <s:Application creationComplete="init()" xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark">
        <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.managers.PopUpManager;
    
            protected function init():void
            {
                var win:MyWindow = MyWindow(PopUpManager.createPopUp(this, MyWindow));
                win.addEventListener(MyEvent.REQUEST_FORWARD, win_requestForwardHandler);
            }
    
            private function win_requestForwardHandler(event:MyEvent):void
            {
                Alert.show(":P");
                var win:MyWindow = MyWindow(event.currentTarget);
                win.removeEventListener(MyEvent.REQUEST_FORWARD, win_requestForwardHandler);
            }
        ]]>
        </fx:Script>
    </s:Application>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have edits to my working tree which I would like to continue working
I have a business object project, which contains composite structure: public class Tree {
I have an object tree which is included in a ResourceDictionary in my application.
I have an object (parse tree) that contains child nodes which are references to
Im working with tree. Every node have object with Tree * values. I read
I have a simple tree which takes the shape below ROOT /\ A B
I have a branch in an SVN tree which contains the source to a
I'm writing a Java Tree in which tree nodes could have children that take
I have to build a tree using the following data which comes from a
I have a table in my database which stores a tree structure. Here are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.