5 Replies Latest reply on Mar 31, 2008 10:27 PM by rlc5611

    Object & Array readability in AS 2

    FrAgFo0d Level 1
      Hi,

      I am having a problem with getting the data which I have put in an Object and an Array.
      I made a script which contains the object playField and the Array tile.

      The data in the array and object must be used to determine the position of movieclips.
      However in some functions the data in the array or in the object cannot be read.

      Please see the code I attached.


      The things that do work:
      - the object and array are created and work fine.
      - the for loop works great and creates 24 movieclips
      - in these 24 movieclips the movieclips named 1 to 24 are placed correctly
      - the button btn_scramble is placed correctly

      This doesn't work:
      - the placement of the gameWhite will work hover it will not be placed on the X and Y position of playField.posX and playField.posY;
      - tracing the playField object ( trace(playField); ) in the placeGameWhite() function will show: [object Object]
      - However tracing the posX of the playField object in this same function will show: undefined;
      - The same happens with tracing tile and e.g. tile[4];

      When I put the same traces in the this.btn_scramble.onRelease function I get the same results.

      I am using Flash 8, with Actionscript 2.

      Can someone help me out?
      I really do not understand why it is giving me such a hard time.

      Regards,

      Bart-Jan

        • 1. Re: Object & Array readability in AS 2
          rlc5611 Level 1
          When you iterate through this:

          this.attachMovie("mc_spelWhite", "mc_spelWhite", this.getNextHighestDepth());

          You are progressively creating multiple MC instances of the exact same instance name at different depths. Flash has no clue what to do with them.
          • 2. Re: Object & Array readability in AS 2
            rlc5611 Level 1
            I admit I don't fully understand what you are trying to do but look at this one modification to two of your functions.

            If I misunderstood and you are trying to create multiple instances, then use a counter of some sort so you can give each instance a unique name.

            BTW, I never can get your object properties to show as undefined. playField.posY and playField.posX are accessible from anywhere in your script that I tried to trace.
            • 3. Re: Object & Array readability in AS 2
              FrAgFo0d Level 1
              I am sorry but it doesn't work for me.
              If you place a trace in the placeGameWhite function (to trace the playField.posX) like this:

              placeGameWhite = function() {
              trace(playField.posX);
              this.attachMovie("mc_spelWhite", "mc_spelWhite", saveDepth);
              this.mc_spelWhite._y = playField.posY;
              this.mc_spelWhite._x = playField.posX;
              };

              What do you see in your trace?
              I will get an: undefined
              though I expect a '150'

              well basically thats my problem.

              And thats not solved either...
              I am getting frustrated because it worked fine and I do not see why it suddenly changed ....
              • 4. Re: Object & Array readability in AS 2
                rlc5611 Level 1
                I'm not at Flash at the moment but I did do that trace earlier and it worked fine. You might try copying and replacing all those variable names. Sometimes Flash does go whacky.

                But you do have a problem with instance names and depths if that button is pressed more than once.
                • 5. Re: Object & Array readability in AS 2
                  rlc5611 Level 1
                  I tried again. Nothing about your original script or modified script will return undefined for trace(playField.posX);. It always returns 150.