8 Replies Latest reply on Aug 16, 2006 6:10 PM by injpix

    Arrays Project

    sbryner Level 1
      Hello all

      Please check out this html page to see if anybody can give me a simple way or
      a little more help with arrays to complete this supposedly fun project that's kicking
      my shines.

      thank you all who've tried to help my cram this info into my brain.

      Click Here To Go To The Page
        • 1. Re: Arrays Project
          blemmo Level 1
          Ok, I don't know what you're trying to do here, but maybe it will help to get you going:
          First, arrays start at index 0, not 1. You can also use Array.push() to add an item on the next free position, instead of doing it by Array[x] = yz;
          Then it seems you want to use objects in your array. This can be done by using the {} as an object constructor, like this:
          var obj = {prop1:value1, prop2:value2}

          So the array creation might be like this, with the object creation inside the push() function:

          var myArray:Array = new Array();
          myArray.push( {price:100, picture:"1.jpg", description:"my stuff"} );

          You can access the object members in a certain array index like that:
          theprice = myArray[0].price;

          • 2. Re: Arrays Project
            sbryner Level 1
            can you use a variable for the index?
            say there is an input text with a number "1" in the field

            myNum = inputText.text;
            theprice = myArray[myNum].price;
            • 3. Re: Arrays Project
              blemmo Level 1
              Yep, but inputText.text will be a string type. Convert it to a number with parseInt(). If it's user input, you might want to check if it's valid; parseInt returns NaN when the input is not a number, so you could check that before you use it.

              myNum = parseInt(inputText.text);
              if ( isNaN(myNum) ){
              // bad input
              else {
              theprice = myArray[myNum].price;

              • 4. Re: Arrays Project
                sbryner Level 1
                Thanks Blemmo,
                not sure if you could see the html. I tried clicking on the link and it didn't work

                try this.

                so, see if this sounds right to you?

                New Link to Page
                • 5. Re: Arrays Project
                  sbryner Level 1
                  somethings wrong with this code: syntax error.



                  btn_mc.onRelease =function(){
                  myNum = parseInt(inputText.text);
                  if ( isNaN(myNum) ){

                  theprice = myArray[myNum].price;

                  dynamicTextPrice_txt.text =theprice;
                  dynamicTextDescription_txt.text= thedescription;
                  • 6. Re: Arrays Project
                    crazyjoemilan Level 2
                    w/o looking at it too deep, it seems you have an extra ; on the end of i++...

                    should be


                    is that what you're asking?
                    • 7. Re: Arrays Project
                      sbryner Level 1
                      I've figured out most of the code now but now I'm getting syntax error on my "if... else.." statement.

                      it appears everything is ok so I don't get it. Only thing I can think of is you can't have these three lines together.

                      } else {
                      for( ...){
                      if( ....)

                      here's the code:
                      • 8. Re: Arrays Project
                        injpix Level 3
                        Tip: always kept your code organized.