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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:35:17+00:00 2026-05-19T02:35:17+00:00

I am trying to make a Xml Image Menu that on button click goes

  • 0

I am trying to make a Xml Image Menu that on button click goes to specific frame label.

The Loop works, the Images and Text Loads without problems.

My Problems:

  • The items don’t center in stage (only
    the last xml item);

  • On button click all the buttons goes
    to the same Label (the label that is
    on the last xml item);

MY CODE:

Variables:

//CREATE VARIABLES FOR XML
var columns:Number;
var my_total:Number;
var my_menu:XMLList;
var item_label:String;
var x_counter:Number = 0;
var y_counter:Number = 0;

Load Xml, I Explain in comments everythings that works or not:

//LOAD XML
var myXMLLoader:URLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("xml.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void
{
    var myXML:XML = new XML(e.target.data);

    //DEFINE THE LENGTH OF THE MENU ITEMS (WORKS WELL)
    my_menu = myXML.ITEM;
    my_total = my_menu.length();
    columns = myXML. @ COLUMNS;

    for (var i:Number = 0; i < my_total; i++)
    {
        //CREATE THE LOOP FOR MOVIE CLIP THAT I HAVE IN LIBRARY WITH THE CLASS "menu_item" 
        var MC:MovieClip = new menu_item();
        var loadIMG:Loader = new Loader;
        // trace(MC); GIVE ME ALL THE XML ITEMS SO WORKS GOOD
        addChild(MC);

        //To CENTER ALL OBJECTS IN MC (NOT WORKS- ONLY CENTERS THE LAST ITEM OF THE XML)
        function resizeHandler(e:Event):void
        {
            MC.x = (MC.stage.stageWidth / 2) - (MC.width / 2);
            MC.y = (MC.stage.stageHeight / 2) - (MC.height / 2);
        }
        stage.addEventListener(Event.RESIZE, resizeHandler);
        stage.dispatchEvent(new Event(Event.RESIZE));

        //DISPLAY MENU ITEMS IN A GRID WITH COLUMNS (WORKS WELL)
        MC.x = (MC.width+10)*x_counter;
        MC.y = (MC.height+100)*y_counter;

        if (x_counter + 1 < columns)
        {
            x_counter++;
        }
        else
        {
            x_counter = 0;
            y_counter++;
        }

        //TO LOAD IMAGES AND TEXT FOR THE MENU (WORKS WELL)
        loadIMG.load(new URLRequest (my_menu[i].@IMAGE));
        MC.container_mc.img_mc.addChild(loadIMG);
        MC.container_mc.title_mc.text = my_menu[i]. @ TITLE;

        //TEST
        MC.name = "mc" + i;
        loadIMG.name = "image" + i;

        //ON BUTTON CLICK GO TO LABEL NAME IN XML (NOT WORKS, ALL ITEMS GOES TO THE SAME AND LAST LABEL IN XML)
        MC.addEventListener(MouseEvent.CLICK, callFull);

        //var test = my_menu[i.target.name].@LABEL; //(FAILED TEST TO TARGET THE LABELS)
        var go_labels = my_menu[i]. @ LABEL;

        function callFull(e:MouseEvent):void
        {
            labels_mc.gotoAndStop(go_labels);

        }


    }
}

XML:

<MENU COLUMNS="2">
    <ITEM IMAGE="img/1.jpg" TITLE="title 1" LABEL="label 1"></ITEM> 
    <ITEM IMAGE="img/2.jpg" TITLE="title 2" LABEL="label 2"></ITEM> 
    <ITEM IMAGE="img/3.png" TITLE="title 3" LABEL="label 3"></ITEM> 
    <ITEM IMAGE="img/4.png" TITLE="title 4" LABEL="label 4"></ITEM>                         
</MENU>

Thanks

  • 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-19T02:35:17+00:00Added an answer on May 19, 2026 at 2:35 am

    I found a couple of errors in your code, tried to fix them quickly, see below and let me know how it works now.

    //CREATE VARIABLES FOR XML
    var columns:Number;
    var my_total:Number;
    var my_menu:XMLList;
    var item_label:String;
    var x_counter:Number = 0;
    var y_counter:Number = 0;
    
    //LOAD XML
    var myXMLLoader:URLLoader = new URLLoader();
    myXMLLoader.load(new URLRequest("xml.xml"));
    myXMLLoader.addEventListener(Event.COMPLETE, processXML);
    
    function processXML(e:Event):void
    {
        var myXML:XML = new XML(e.target.data);
    
        //DEFINE THE LENGTH OF THE MENU ITEMS (WORKS WELL)
        my_menu = myXML.ITEM;
        my_total = my_menu.length();
        columns = myXML. @ COLUMNS;
    
        for (var i:Number = 0; i < my_total; i++)
        {
            //CREATE THE LOOP FOR MOVIE CLIP THAT I HAVE IN LIBRARY WITH THE CLASS "menu_item" 
            var MC:MovieClip = new menu_item();
            MC.id = i;
            MC.label = my_menu[i]. @ LABEL;
            MC.name = "mc" + i;
    
            //DISPLAY MENU ITEMS IN A GRID WITH COLUMNS (WORKS WELL)
            MC.x = (MC.width+10)*x_counter;
            MC.y = (MC.height+100)*y_counter;
    
            if (x_counter + 1 < columns)
            {
                x_counter++;
            }
            else
            {
                x_counter = 0;
                y_counter++;
            }
    
            var loadIMG:Loader = new Loader;
            loadIMG.name = "image" + i;
    
            MC.container_mc.img_mc.addChild(loadIMG);
            MC.container_mc.title_mc.text = my_menu[i]. @ TITLE;
    
            addChild(MC);
    
            //ON BUTTON CLICK GO TO LABEL NAME IN XML (NOT WORKS, ALL ITEMS GOES TO THE SAME AND LAST LABEL IN XML)
            MC.addEventListener(MouseEvent.CLICK, callFull);
            //TO LOAD IMAGES AND TEXT FOR THE MENU (WORKS WELL)
            loadIMG.load(new URLRequest (my_menu[i].@IMAGE));
    
        }
    
        stage.addEventListener(Event.RESIZE, resizeHandler);
        stage.dispatchEvent(new Event(Event.RESIZE));   
    }
    
        function callFull(e:MouseEvent):void
        {
            //e.currentTarget should return the MC instance you clicked
            e.currentTarget.labels_mc.gotoAndStop(e.currentTarget.label);
    
        }
    
        //To CENTER ALL OBJECTS IN MC (NOT WORKS- ONLY CENTERS THE LAST ITEM OF THE XML)
        function resizeHandler(e:Event):void
        {
            var i:uint = 0;
            for (; i < my_total; i++ )
            {
                this["mc" + i].x = stage.stageWidth / 2 - this["mc" + i].width / 2;
                this["mc" + i].y = stage.stageHeight / 2 - this["mc" + i].height / 2;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a generic PL/SQL procedure to export data in specific XML format,
I'm trying to make a context menu for a control that is linked to
I am trying to make a div, that when you click it turns into
I'm trying to just make an activity that simply loads a random image when
I'm trying to make a dynamic image gallery from and xml. From my tutorials,
I'm trying to make two XML attributes to be mutually exclusive. How can one
I'm currently trying to read in an XML file, make some minor changes (alter
Trying to make a make generic select control that I can dynamically add elements
I'm trying to make the case for click-once and smart client development but my
I'm trying to make it so that as long as a user is touching

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.