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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:19:19+00:00 2026-05-12T15:19:19+00:00

This is related to other question . But never mind it. I’ve fixed part

  • 0

This is related to other question. But never mind it. I’ve fixed part of it.

I have a DataGrid, its data provider is a ArrayCollection, and i want it to parse all itens in it (Object Type) to a String.

For that I’ve done a "for each" loop, it manages to get the Object and its values, but if i have more that one object it only gets the last object, don’t know why.


First i will show how these items are added to the ArrayCollection, that way you will understand the rest much easily.

In the Main Application i have the ArrayCollection:

<mx:ArrayCollection id="collection">

Then in other Component there is a Add Item Menu, and when you add a item:

private function fazerEncomenda():void
{
    var novoitem:Object;
    novoitem = new Object();
    novoitem.id = "consumivel"+getProdInfo.lastResult.consumivel.id;
    novoitem.tinteiroid = getProdInfo.lastResult.consumivel.id;
    novoitem.label = getProdInfo.lastResult.consumivel.nome;
    novoitem.ref = getProdInfo.lastResult.consumivel.refmarca;
    novoitem.marca = getProdInfo.lastResult.consumivel.marca;
    novoitem.genero = genero.text;
    novoitem.quantidade = quantidade.text;
    Application.application.collection.addItem(novoitem);
}

Then in another component the DataGrid as its dataProvider Binded to the ArrayCollection

<mx:DataGrid id="compras" x="0" y="0" width="556" dataProvider="{Application.application.collection}" editable="false">
        <mx:columns>
            <mx:DataGridColumn headerText="ID" dataField="tinteiroid" visible="false"/>
            <mx:DataGridColumn headerText="Nome" dataField="label" width="120" />
            <mx:DataGridColumn headerText="Ref" dataField="ref" width="100"/>
            <mx:DataGridColumn headerText="Marca" dataField="marca" width="100"/>
            <mx:DataGridColumn headerText="Género" dataField="genero" width="155"/>
            <mx:DataGridColumn headerText="Quantidade" dataField="quantidade" width="81"/>
        </mx:columns>
    </mx:DataGrid>

And when a Button is pressed the function to get all Objects and its values to an String.

And in this function its where it only gets the last item, in the ArrayCollection.

for each (novoitem in compras.dataProvider)
{
    finish += "TinteiroID:"+novoitem.tinteiroid+"#TinteiroLABEL:"+novoitem.label+"#TinteiroREF:"+novoitem.ref+"#TinteiroMARCA:"+novoitem.marca+"#TinteiroGENERO:"+novoitem.genero+"#TinteiroQUANTIDADE:"+novoitem.quantidade+"#FIMPROD#";
    trace(finish);
}

And of course the Vars used in the function:

private var finish:String;
private var novoitem:Object

As you see in the finish var i used += so it adds it self and the next object. Instead he adds null. And only one null event if there was 3 items before.

Don’t know whats the problem with this loop.

Please Help. I’m loosing my mind here.

PS: Sorry for any bad English, its been 3 hours in this. And no progress.

EDIT: Missing Vars Declaration Added

  • 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-12T15:19:20+00:00Added an answer on May 12, 2026 at 3:19 pm

    An easier way to do all this (admittedly not with the labels you specified) is to just use ActionScript’s built in ObjectUtil.toString method.

    You would write something like this:

    import mx.utils.ObjectUtil;
    
    public function dumpObj():void {
        myTextField.text = ObjectUtil.toString(obj);
     }
    

    This should pretty much print out every property of every multiple / nested object you have.

    HOWEVER – you should make a fundamental change to your component if you want it to be reusable. You need a getter/setter for your collection. In the component, add this code:

    [Bindable]
    private var _myCollection:ArrayCollection;
    
    public function set myCollection (data:ArrayCollection) : void {
        _myCollection = data;
    }
    
    public function get myCollection () : ArrayCollection {
        return _myCollection;
    }
    

    There are several other ways to do this – look it up if you need something different.
    In your datagrid, use the private ArrayCollection variable like this:

    <mx:DataGrid id="compras" x="0" y="0" width="556" dataProvider="{_myCollection}" editable="false">
        <mx:columns>
                <mx:DataGridColumn headerText="ID" dataField="tinteiroid" visible="false"/>
    ...
    

    In the main application, you can populate your component like this:

    <kgtm:myComponent x="0" y="20" myCollection="{queryDataAC}"
    

    And you name your ArrayCollection like this:

    <mx:ArrayCollection id="queryDataAC">
    

    in your top level Application code, you define the kgtm namespace, so you can use your custom component, like so:

    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:kgtm="com.kgtm.*"
    

    Then put your component in the folder corresponding to this namespace definition.

    This all leads to the final object print utility – which you define on the component, as it is the only thing that should know about how to print out it’s data.

    Define a public function, and get it to print out the private ArrayCollection data, using ObjectUtil or your own method.

    public var getLastQueryOutput () : String {

    private var output:String = "";
    private var len:int = _myCollection.length;
    for (var i:int = 0; i <len; i++)   {
        output = output + 
        "TinteiroID:"+_myCollection[i].tinteiroid+
        "#TinteiroLABEL:"+_myCollection[i].label+
        "#TinteiroREF:"+_myCollection[i].ref+
        "#TinteiroMARCA:"+_myCollection[i].marca+
        "#TinteiroGENERO:"+_myCollection[i].genero+
        "#TinteiroQUANTIDADE:"+_myCollection[i].quantidade+
        "#FIMPROD#";
    
    }
    trace(output);
    

    }

    Hopefully this will help. If you name the object correctly as you are putting it into the ArrayCollection, you can again just use ObjectUtil as I stated at the top.

    Casp – Check out more of my (and my colleagues) blog entries here

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

Sidebar

Related Questions

This is related to my other question , but I felt like I should
I've looked at other questions on Stack Overflow related to this question, but none
This related to my other question . I have this table CREATE OR REPLACE
This is related to my other question: Managing Foreign Keys I am trying to
This question is related to this other question I recently asked... cf.net exception and
This question is related to my other question How to redirect to Login page
This is related to a question I asked the other day on how to
This is a followup question to my other widget-related question . I'd like to
This may sound as a non related coding question but it's directly related :
This question is in a way related to this other question: Sphinx Filters -

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.