Skip to main content
Known Participant
January 20, 2013
Answered

object problem

  • January 20, 2013
  • 1 reply
  • 1047 views

hi how are you guys ? i hope you all fine ..

here ..

iam having problem with object , i want to make the object properties arrays .. 

am gonna explain the code that will be better

first i want to create object

a:Object = new  Object()

a.itemname = itemnamevar

a.itemprice = itempricevar

this the object and the itemnamevar and the itempricevar are also object (2 text boxes) so the variables contents

itemnamevar = item.text

itempricevar = int(price.text)

so when i enter the name and the price for the customers it will be only one place

and it is going to change every time 

for ( i:string in a){

...

trace()    // here they gonna change every time  , i mean after entring another price and name

}

so .. i need to put these in array , but i realy dont know how to this in object class

thank you

This topic has been closed for replies.
Correct answer Ned Murphy

The array will contain each object you create.  In having that, you will have every property of each object accssible vi the object in the array.

If I missed your intentions, which is quite possible, and your quest for an array is to have arrays for the properties, meaning you have only one Object but it should have arrays of the same properties, then you would want to use something like...

var a:Object = new Object();

a.itemname = new Array();

a.itemprice = new Array();

a.itemname.push(itemnamevar);

a.itemprice.push(itempricevar)

1 reply

Ned Murphy
Legend
January 20, 2013

It is not clear to me what you are trying to do but if you think you need an array then just create an array the same way you went about creating the object.

var objects:Array = new Array();

var a:Object = new Object();

a.itemname = itemnamevar

a.itemprice = itempricevar

objects.push(a);

That ends up giving you an array of objects, currently holding just the one Object "a".  If that is not what you intend, please explain further what is different about what you want.

Known Participant
January 20, 2013

is he now going to push all the properties in the array??

i mean this "objects.push(a);"  a.itemname and  a.itemprice will be in the objects array?

like when we trace objects like this (objects[0]) we will get them , the price and the name

thank you for your replay

Ned Murphy
Ned MurphyCorrect answer
Legend
January 20, 2013

The array will contain each object you create.  In having that, you will have every property of each object accssible vi the object in the array.

If I missed your intentions, which is quite possible, and your quest for an array is to have arrays for the properties, meaning you have only one Object but it should have arrays of the same properties, then you would want to use something like...

var a:Object = new Object();

a.itemname = new Array();

a.itemprice = new Array();

a.itemname.push(itemnamevar);

a.itemprice.push(itempricevar)