A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: This wont work for somereason [as2]

  1. #1
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292

    This wont work for somereason [as2]

    Hey, i've got my array, and then after it i've set an array value.
    The price of the array to .. what ever it is.
    Money is a variable i've got as a 1000
    There is no syntax errors.
    And my items are added to the correct slots.
    Just my money/price arnt being affected at all.

    I've been working on this for a very long time now, trying to get it perfect.
    And i am soon, going to take it further. with xml.
    But i would like to get this done properly asap.

    Thank you in advance for any help possible.


    PHP Code:
    shop = new Array();
    shop[0]=(attachMovie("Sword","sword",12));
    shop[1] =(attachMovie("Shield","shield",11));
    shop[2]=(attachMovie("Ring","ring",9));
    ----------------------------------------------------
    shop[0].price 500;
    shop[1].price 50;
    shop[2].price 100;
    ---------------------------------------------------
    function 
    addToslot(item) {
    if (
    money >= price){
        
    money price;
        
    item._x = eval("bagslot"+bagslotnumber)._x;
        
    item._y = eval("bagslot"+bagslotnumber)._y;
        
    bagslotnumber++;
    } else
        if (
    money price){
        
    //return to coordinates
    }

    Ryan :]

  2. #2
    Pumpkin Carving 2008 ImprisonedPride's Avatar
    Join Date
    Apr 2006
    Location
    Grand Rapids MI
    Posts
    2,379
    Try money -= price.
    The 'Boose':
    ASUS Sabertooth P67 TUF
    Intel Core i7-2600K Quad-Core Sandy Bridge 3.4GHz Overclocked to 4.2GHz
    8GB G.Skill Ripjaws 1600 DDR3
    ASUS ENGTX550 TI DC/DI/1GD5 GeForce GTX 550 Ti (Fermi) 1GB 1GDDR5 (Overclocked to 1.1GHz)
    New addition: OCZ Vertex 240GB SATA III SSD
    WEI Score: 7.6

  3. #3
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292
    Thank you for getting back to me so quick.
    But that unfortunately, instead of taking the price away.
    Says NaN.
    Ryan :]

  4. #4
    Senior Member
    Join Date
    Oct 2006
    Posts
    221
    um, it appears that the variable "price" that you are referencing to is not there. this is because each item in the array has the price variable. to reference to each individual price, you want:
    if (money >= shop[0].price){
    money -=shop[0].price;
    item._x = eval("bagslot"+bagslotnumber)._x;
    item._y = eval("bagslot"+bagslotnumber)._y;
    bagslotnumber++;
    } else
    if (money < shop[0].price){
    //return to coordinates
    }

    you'd have to reference each item of the shop array by shop[1].price, shop[2].price and so on. this could get tedius, so a loop would be wise here.

    so it then becomes:
    for(var i=0;i<shop.length;i++){
    if (money >= shop[i].price){
    money -=shop[i].price;
    item._x = eval("bagslot"+bagslotnumber)._x;
    item._y = eval("bagslot"+bagslotnumber)._y;
    bagslotnumber++;
    } else
    if (money < shop[i].price){
    //return to coordinates
    }
    }
    i think that should work, forgive me if i'm wrong though

  5. #5
    Senior Member
    Join Date
    Jan 2006
    Location
    USA
    Posts
    383
    I'm guessing you're calling your function like this:
    Code:
    addToSlot(shop[0]);
    If so, the quickest fix would be adding this:

    Code:
    function addToslot(item) {
       var price:Number = item.price;
       ...
    }

  6. #6
    Ryan :D ryanp321's Avatar
    Join Date
    Nov 2007
    Location
    Wallasey
    Posts
    292
    Squidgie and afternoonDelite.
    I tried both, wondering which works best.
    And they both work great.
    Thank you for your help.
    Ryan :]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center