Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Why Does My Code Return [object Object]?

Guest
Jan 16, 2016 Jan 16, 2016

I want it to return what I enter in the text boxes but the price, size, and username all have to remain paired up. The data also needs to remained stored so the next time someone comes and enters in their own data the previous data isn't deleted. Later on I want to be able to sort columns by Price, by Size, and by Username. So why does it keep returning [object Object] with anything I enter? Thank you so much for any help you can give me!!

var wheat:Array = new Array()

var priceS:String

var price:int

var sizeS:String

var size:int

var username:String

submit_btn.addEventListener(MouseEvent.CLICK, wheatBidSubmit);

function wheatBidSubmit(event:MouseEvent):void

{   

    priceS = (price_txt.text)

    price = int(priceS)

    sizeS = (size_txt.text)

    size = int(sizeS)

    username = (username_txt.text)

   

    wheat.push({Price:price, Size:size, Username:username})

    trace (wheat)

}

TOPICS
ActionScript
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 16, 2016 Jan 16, 2016

use:

function traceF(a:Array):void{

for(var i:int=0;i<a.length;i++){

trace(i,a.price);

}

}

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Community Expert ,
Jan 16, 2016 Jan 16, 2016

that's expected.

to inspect an array of objects, use:

function traceF(a:Array):void{

for(var i:int=0;i<a.length;i++){

for(var s:String in a){

trace(i,s,a);

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 16, 2016 Jan 16, 2016

How do I access one of the items, say Price for example. I want to see just what the Price is. What you gave me works great, but it shows me all three components

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2016 Jan 16, 2016

use:

function traceF(a:Array):void{

for(var i:int=0;i<a.length;i++){

trace(i,a.price);

}

}

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 16, 2016 Jan 16, 2016

So I have a 2 column DataGrid with Price in the left column and Size in the right column. How do I sort it so that it sorts Price in ascending order but Size in descending order? Like this...

$1.00     2

$2.00     4

$2.00     3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 16, 2016 Jan 16, 2016

like this:

wheat.sort(sortF);

function sortF(a:Object,b:Object):int{

if(numberF(a.price)<numberF(b.price)){

return -1;

} else if(numberF(a.price)>numberF(b.price)){

return 1;

} else if(numberF(a.price)==numberF(b.price)){

if(a.size<b.size){

return -1;

} else if(a.size>b.size){

return 1;

} else {

return 0;

}

}

}

function numberF(price):Number{

//convert your price into a number and return it.  i'm not sure if your price is a string like $1.00 or something else

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2016 Jan 17, 2016

What is "numberF" in this example?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2016 Jan 17, 2016

Oh oh oh!!! I see it now! Thank you sooo very much, you are absolutely amazing! If I could help you I would but with this stuff your miles ahead. Thanks  so much, I'm sure I'm not finished with all my questions yet

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2016 Jan 17, 2016

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 17, 2016 Jan 17, 2016

If I have two arrays, one for bid prices and one for sell prices, how do I tell the computer to check and see when the price of one matches the price of the other at any point and then get rid of that price. As with before there is also "Size" and "Username" within each array element so they will have to be removed as well. So you could enter $2, $3, $4, $3 to the bid array and $6, $5, $1, $4 to the sell array and the computer sorts it perfectly thanks to your advice earlier. But now how to I get it to remove a $4 from both arrays because it shows up on both sides?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 17, 2016 Jan 17, 2016

you can use the splice() method to remove an array element.  eg, to remove the ith element

wheat.splice(i,1)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 22, 2016 Jan 22, 2016

Hey again! Hopefully you still follow this question because I've got another problem. So right now I have two arrays that consist of a Price, Size, and Username in each element. One array is for buying (Bids) and the other is for selling (Ask). When data gets entered, it is displayed in two datagrids, one for Bids, one for Asks. But what I need now is a way to check and see if the same price has been entered on both sides of the table. So if $10.00 is entered on a Bid and $10.00 is entered on an Ask. If the prices are the same I need to delete that row on both the Bid side and the Ask side. What is giving me problems is that I can delete elements no problem, but if there are only 3 elements on the Bid side and say 2 elements on the ask side, I can't get the computer to "search". Plus! In the future I want this to happen. If there are prices that are the same the next thing is to look at Sizes. If the prices and the sizes are the same, the whole element is to be deleted. But if say there is an Ask for $10.00, Size 10, and a Bid for $10.00, Size 5, I need the bid to be removed and the ask to go to $10.00, Size 5. Just subtracting the original Ask size from the Bid size. Good luck, you're my only hope right now. I'll send you my code so you're not stabbing in the dark. If there's anything I can do for you, let me know, thanks!

import fl.controls.DataGrid;

import fl.controls.ScrollPolicy;

import fl.data.DataProvider;

var wheatBid: Array = new Array()

var priceSBid: String

var priceBid: Number

var sizeSBid: String

var sizeBid: int

var usernameBid: String

var wheatAsk: Array = new Array()

var priceSAsk: String

var priceAsk: Number

var sizeSAsk: String

var sizeAsk: int

var usernameAsk: String

var price: Number

var dg: DataGrid = new DataGrid();

dg.setSize(217, 218);

dg.move(0, 103);

dg.columns = ["Price", "Size", "Username"];

addChild(dg)

var DG: DataGrid = new DataGrid();

DG.setSize(229, 218);

DG.move(220, 103);

DG.columns = ["Price", "Size", "Username"];

addChild(DG)

function addBidArray() {

    wheatBid.sortOn(['Price', 'Size'], Array.DESCENDING | Array.NUMERIC)

    var i: uint;

    var totalRowsBid: uint = wheatBid.length;

    var dp: DataProvider = new DataProvider();

    for (i = 0; i < totalRowsBid; i++) {

        dp.addItem({

            Price: "$" + (wheatBid.Price).toFixed(2),

            Size: wheatBid.Size,

            Username: wheatBid.Username

        });

    }

    dg.dataProvider = dp;

    addChild(dg);

}

function addAskArray() {

    wheatBid.sortOn(['Price', 'Size'], Array.DESCENDING | Array.NUMERIC)

    var o: uint;

    var totalRowsAsk: uint = wheatAsk.length;

    var DP: DataProvider = new DataProvider();

    for (o = 0; o < totalRowsAsk; o++) {

        DP.addItem({

            Price: "$" + (wheatAsk.Price).toFixed(2),

            Size: wheatAsk.Size,

            Username: wheatAsk.Username

        });

    }

    DG.dataProvider = DP;

    addChild(DG);

}

function compare(wheatAsk: Array, wheatBid: Array) {

    for (var e: int = 0; e < wheatBid.length; e++) {

        if (wheatAsk.Price == wheatBid.Price) {

            trace("Win")

            wheatBid.splice(e, 1)

            wheatAsk.splice(e, 1)

            addBidArray()

            addAskArray()

        }

    }

}

wheatBidSubmit_btn.addEventListener(MouseEvent.CLICK, wheatBidSubmit);

function wheatBidSubmit(event: MouseEvent): void {

    priceSBid = (wheatSubmitBidPrice_txt.text)

    priceBid = Number(priceSBid)

    sizeSBid = (wheatSubmitBidSize_txt.text)

    sizeBid = int(sizeSBid)

    usernameBid = (wheatBidUsername_txt.text)

    if ((priceBid > 0) && (sizeBid > 0) && (usernameBid.length > 0)) {

        wheatBid.push({

            Price: priceBid,

            Size: sizeBid,

            Username: usernameBid

        })

        addBidArray()

        compare(wheatAsk, wheatBid)

    }

}

wheatAskSubmit_btn.addEventListener(MouseEvent.CLICK, wheatAskSubmit);

function wheatAskSubmit(event: MouseEvent): void {

    priceSAsk = (wheatSubmitAskPrice_txt.text)

    priceAsk = Number(priceSAsk)

    sizeSAsk = (wheatSubmitAskSize_txt.text)

    sizeAsk = int(sizeSAsk)

    usernameAsk = (wheatAskUsername_txt.text)

    if ((priceAsk > 0) && (sizeAsk > 0) && (usernameAsk.length > 0)) {

        wheatAsk.push({

            Price: priceAsk,

            Size: sizeAsk,

            Username: usernameAsk

        })

        wheatAsk.sort(sortF)

        function sortF(a: Object, b: Object): Number {

            if (numberF(a.Price < numberF(b.Price))) {

                return -1

            } else if (numberF(a.Price) > numberF(b.Price)) {

                return 1

            }

            if (numberA(a.Size) < numberA(b.Size)) {

                return 1

            } else if (numberA(a.Size) > numberA(b.Size)) {

                return -1

            } else {

                return 0

            }

            function numberF(priceAsk): Number {

                return priceAsk

            }

            function numberA(sizeAsk): int {

                return sizeAsk

            }

        }

        addAskArray()

        compare(wheatAsk, wheatBid)

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2016 Jan 22, 2016

that's getting a bit more involved than i do for free.  if you can narrow your question, i'll answer it here.

but i won't go through more than 20-30 lines of code and lengthy questions that require more than a minute or two to understand, unless i'm hired.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 22, 2016 Jan 22, 2016

Totally understand! So say I have two arrays, ArrayOne and ArrayTwo. In each element there is a Price and a Size. All I'm concerned about is Price. So say I enter $10, $30, $20 into ArrayOne (in that order). The computer sorts it like you taught me. And then someone enters $40, $20 into ArrayTwo. computer sorts it. How can I make it so that the computer looks at the two arrays and determines if there is a point where the same price appears in both arrays and deletes them. So in this case it would delete the element with $20 in ArrayOne and ArrayTwo

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2016 Jan 22, 2016
LATEST

// sellBidF will remove one matched price in both arrays and return an array of two objects removed: the matched bid object and the matched ask object

function bidSellF(bidA:Array,askA:array):Array{

for(var i:int=bidA.length-1;i>=0;i--){

for(var j:int=askA.length-1;j>=0;j--){

if(bidA.price==askA.price){

return [bid.splice(i,1),askA.splice(j,1)];

}

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines