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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:51:31+00:00 2026-06-07T12:51:31+00:00

I’m using Flash Builder 4.6 to create an app for a uni project. I

  • 0

I’m using Flash Builder 4.6 to create an app for a uni project. I have a custom Spark component, and I need to dynamically create a number of instances of that component at runtime depending on the number of XML elements returned via a PHP script.

That might be a bit confusing, so let me write the steps:
1) The application sends an HTTPService request to a PHP script hosted on the server.
2) The PHP accesses the SQL database and returns a series of XML data.
3) The ActionScript dynamically creates X instances of my custom Flex component, where X is the number of data in the XML.

Here’s the code I’ve got so far (untidy because I’m trying to make it work):

ActionScript:

        [Bindable]
        public var holderArray:Array = new Array(100);

        public function createMenu(e:MouseEvent):void {
            var count:int = 0;
            var curMenuItem:menuItemContainer = new menuItemContainer();
            while (count < loadedMenu.length){
                curMenuItem.itemName = loadedMenu.getItemAt(count).name;
                curMenuItem.itemDesc = loadedMenu.getItemAt(count).description;
                curMenuItem.itemPrice = numForm.format(loadedMenu.getItemAt(count).price);                  
                curMenuItem.imageFile = loadedMenu.getItemAt(count).url;
                //curMenuItem.y = count * 120
                //menuItemGroup.addElement(curMenuItem);
                holderArray[count] = curMenuItem;
                count ++;
            }
            //testString = holderArray[1].itemName;
            var count2:int = 0;
            for each (var menuItem:menuItemContainer in holderArray){
                menuItem.name = "menuItem" + count2;
                menuItem.id = "menuItem" + count2;
                //testString += menuItem.name;
                menuItemGroup.addElement(menuItem);
                count2++;
            }
        }

MXML:

<s:VGroup id="menuItemGroup" x="40" y="150">
</s:VGroup>

What seems to be happening with that code is that each of my three XML data that get returned are being used in instances of menuItemContainer, but when each one is added to menuItemGroup, it’s overwriting the one that’s already there. I’m not sure if the item is actually getting overwritten, or if the new item is just sitting atop the earlier ones, but if the latter is true I can’t find a way to arrange the components. I’ve tried setting menuItem.y in the loop (as a function of count2), but to no avail.

Thanks in advance for any and all suggestions/answers.
Benjamin.

  • 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-06-07T12:51:33+00:00Added an answer on June 7, 2026 at 12:51 pm

    Put this line

    var curMenuItem:menuItemContainer = new menuItemContainer();
    

    inside your while loop. With your code as it is you are only creating one instance of menuItemContainer then continually changing the properties of that one menuItemContainer in your while loop. Instead you need to create a new, different instance of menuItemContainer with each iteration of the loop.

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

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't

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.