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 540945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:17:33+00:00 2026-05-13T10:17:33+00:00

Hello Fellow stackoverflowers, I´m stuck writing a piece of code. I have application with

  • 0

Hello Fellow stackoverflowers,

I´m stuck writing a piece of code.
I have application with a viewstack witch load 5 modules.
each module is loaded via the moduleLoader tag and they all have an id.

Every loaded module has a context menu. the context menu has 5 menuItems.
one menuItem for each view for the viewstack.

The context menu is loaded via xml.

this is my application file.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
      layout="absolute"
      backgroundColor="#b1b1b1"
      backgroundGradientColors="[#b1b1b1,#252525]">

<mx:Script>
<![CDATA[
import mx.core.Container;


        //change viewstack views via modules context menu
        public function switchView(viewId:String):void
     {
         var container:Container = Container(tops.getChildByName(viewId));
         if (container != null)
         {
             tops.selectedChild = container;
         }
     }
]]>
</mx:Script>

<mx:ViewStack id="tops" width="100%" height="100%">
  <mx:ModuleLoader id="admin" url="view/admin.swf" width="100%" height="100%"/>
  <mx:ModuleLoader id="tv" url="view/tv.swf" width="100%" height="100%"/>
  <mx:ModuleLoader id="community" url="view/community.swf" width="100%" height="100%"/>
  <mx:ModuleLoader id="shop" url="view/shop.swf" width="100%" height="100%"/>
  <mx:ModuleLoader id="communicator" url="view/communicator.swf" width="100%" height="100%"/>
</mx:ViewStack>


</mx:Application>

and this is my switch statement in my Module

public function changeView():void{
switch(action) {
case "admin":
    parentApplication.switchView("admin");
break;
case "tv":
    parentApplication.switchView("tv");
break;
case "shop":
    parentApplication.switchView("shop");
break;
case "community":
    parentApplication.switchView("community");
break;
case "default":
    parentApplication.switchView("communicator");
break;
 }
}

and this is my context menu xml

  <mx:XML id="appMenu">
    <root>
        <menuitem enabled="false"/>
        <menuitem label="Administration" action="admin" icon="adminMDI"/>
        <menuitem label="Television" action="tv" icon="tvMDI"/>
        <menuitem label="Community" action="community" icon="communityMDI"/>
        <menuitem label="Shopping Mall" action="shop" icon="shoppingMallMDI"/>
        <menuitem label="Communicator" action="default" icon="communicatorMDI"/>                                                              
    </root>
  </mx:XML>

What i would like to do is switch the views in the viewstack by clicking on one of the menuitems in the context menu.
i can’t communicate from my module to the application.
What am i doing wrong?
what must i do?
Can anybody help me out?

Oyeah before i forget

the xml of the context menu is in the module but, the context menu is in a as file that extensiate a button.

please can any body give me a good example how to accomplish this.

Thank

DJ

  • 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-13T10:17:33+00:00Added an answer on May 13, 2026 at 10:17 am

    I see a couple issues before getting into the multi-module communication.

    First, in your changeView() function, you are declaring the variable action and then switching on it.

    public function changeView():void {
        var action:String;
        switch(action) {
            // action will always be null here.
        }
    }
    

    Because you don’t have a ‘default’ case in your switch statement(s), parentApplication.switchView will never be called.

    Also, for the sake of brevity, you can write switch statements like this:

    switch(action) {
        case "admin":
            parentApplication.changeView("admin");
        break;
        case "tv":
            parentApplication.changeView("tv");
        break;
        case "shop":
            parentApplication.changeView("shop");
        break;
        // ... etc ...
        default:
            // this gets called if action doesn't match anything.
        break;
    }
    

    Finally, you could save yourself even more typing because your action and module ids are the same, you could do this:

    public function changeView(action:String):void {
        parentApplication.changeView(action);
    }
    

    Maybe try those things and then updating your question (also, the XML for your context menus didn’t render correctly in your question). That may help the community solve your issue a little easier.

    UPDATE

    I don’t think the problem is in the module communication. I built a simple project that does what I think you’re looking for. I’ve posted the source below.

    mmodules.mxml

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" implements="interfaces.IApplication">
        <mx:Script>
            <![CDATA[
                import mx.core.Container;
                public function changeView(action:String):void {
                    viewstack.selectedChild = viewstack.getChildByName(action) as Container;
                }
            ]]>
        </mx:Script>
        <mx:ViewStack id="viewstack" width="100%" height="100%">
            <mx:ModuleLoader id="module1" url="views/module1.swf" />
            <mx:ModuleLoader id="module2" url="views/module2.swf" />
        </mx:ViewStack>
    </mx:Application>
    

    interfaces/IApplication.as

    package interfaces {
        public interface IApplication {
            function changeView(action:String);
        }
    }
    

    views/module1.mxml

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Script>
            <![CDATA[
                import interfaces.IApplication;
                import mx.events.MenuEvent;
                import mx.controls.Menu;
                /**
                * Dynamically builds a menu.
                */
                protected function showMenu():void {
                    var m:Menu = Menu.createMenu(null, menuData, false);
                    m.labelField = '@label';
                    m.addEventListener(MenuEvent.ITEM_CLICK, onItemClick);
                    m.show(10, 10);
                }
                /**
                * Handles whenever an item in the menu is clicked.
                */
                protected function onItemClick(e:MenuEvent):void {
                    if(e && e.item && e.item is XML) {
                        changeView(e.item.@action);
                    }
                }
                /**
                * Tells the parent application to switch views.
                */
                protected function changeView(action:String):void {
                    var app:IApplication = parentApplication as IApplication;
                    switch(action) {
                        case 'module1':
                            app.changeView('module1');
                        break;
                        case 'module2':
                            app.changeView('module2');
                        break;
                    }
                }
            ]]>
        </mx:Script>
        <mx:XML format="e4x" id="menuData">
            <root>
                <menuitem label="Module 1" action="module1" />
                <menuitem label="Module 2" action="module2" />
            </root>
        </mx:XML>
        <mx:Button label="Show menu" click="showMenu()" />
    </mx:Module>
    

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 277k
  • Answers 277k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Shouldn't $query="select * from employee where Username='{$usr}' and Password='{$c}'"; be… May 13, 2026 at 2:55 pm
  • Editorial Team
    Editorial Team added an answer you can prefix the array keys with a short string:… May 13, 2026 at 2:55 pm
  • Editorial Team
    Editorial Team added an answer It looks like you're using MagicCookie authentication, which will give… May 13, 2026 at 2:55 pm

Related Questions

Hello fellow C++ programmers. I have, what I hope to be, a quick question
Hello fellow programmers. I have a SQL Server 2005 query that is taking a
Hello there fellow Stackers! I wonder if anybody could tell me what the following
Hello Again my fellow programmers out there, I'm designing and programming from scratch a
Fellow JQuery hackers, hello :-) Suppose you have the following code: $('.links').click(function(){ //Do something

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.