5 Replies Latest reply on Jan 17, 2007 12:45 AM by Ankur Arora

    array confusion

    jagguy99 Level 1
      I have no idea what happens in AS when you try to give an array a value. This is a test program for a larger project. There is a quirk obviously which i don't get.

      I just want to assign an array value inside an event but it fails . I am using arrays of values to make it look messy.

      I can't assign an array inside an an event ?


      var tt:Array=new Array();
      var mLoad:MovieClipLoader = new MovieClipLoader();


      //trace(tt.toString());
      this.createEmptyMovieClip("my0",this.getNextHighestDepth());
      my0.createEmptyMovieClip("myy0",my0.getNextHighestDepth());
      mLoad.loadClip("98img1.jpg",my0.myy0);

      this.createEmptyMovieClip("my1",this.getNextHighestDepth());
      my1.createEmptyMovieClip("myy1",my1.getNextHighestDepth());
      mLoad.loadClip("98img1.jpg",my1.myy1);
      my1._x=100;



      var j:Number;

      for (j=0; j<2; j++)
      {
      // tt[j]=j;/////// This works when i assign it outside the event

      this["my"+j].onPress = function(){

      tt[j]=j;///////////////////////////// THIS FAILS to assign values in array as I get undefined why?
      //this._parent.tt[j]=j;

      }
      }
      trace(tt.toString());
        • 1. Re: array confusion
          Level 7
          > //this._parent.tt[j]=j;

          So does that work when uncommented? it looks like it should
          --
          Jeckyl


          • 2. Re: array confusion
            jagguy99 Level 1
            > //this._parent.tt[j]=j;

            no this fails
            this._parent.tt[j]=j;

            maybe AS wasn't meant to do this because yoy can get values inside the loop but outside the events.
            • 3. Re: array confusion
              Level 7
              ok .. now where is the code that you showed .. is it directly in a frame or
              is it in a class or .... ?

              It would help if you simply uploaded you FLA and provided a link for us to
              download it. What you show (when you use the this._parent) should work,
              given the snippet you provided.
              --
              Jeckyl


              • 4. Re: array confusion
                jagguy99 Level 1
                I want to click on an image and a seperate value appears for each event. I can't get anything to appear.


                import mx.transitions.Tween;

                var nameVars= new LoadVars();
                var txt1:String;
                var st_num:Number;
                var mLoad:MovieClipLoader = new MovieClipLoader();
                var aval:Array= new Array();
                mLoad2 = new MovieClipLoader();
                aval.push("98img1.jpg");
                aval.push("50img2.jpg");



                for (i=0;i<2;i++)
                {
                this.createEmptyMovieClip("mcc"+i,this.getNextHighestDepth());
                this["mcc"+i].createEmptyMovieClip("mccc"+i,this["mcc"+i].getNextHighestDepth());

                this["mcc"+i]["mccc"+i]._x= 100*i;
                //this["mcc"+i]._y=20;
                mLoad.loadClip(aval ,this["mcc"+i]["mccc"+i]);
                }

                this.createEmptyMovieClip("my",this.getNextHighestDepth());
                my._x=250;
                my._y=100;
                //var y=0;
                tt= new Array();
                j=0;

                for (j=0; j<2; j++)
                {
                this["mcc"+j].arrayIndex=j;

                this["mcc"+j].onPress = function()
                {
                txt2.text=this._parent["mcc"+j].arrayIndex;
                tt[j]=j;
                trace(tt.toString());
                trace(j);
                //mLoad.loadClip("98img1.jpg",my);
                mLoad2.loadClip(aval[j],my);
                }
                }
                • 5. array confusion
                  Ankur Arora Level 1
                  Try This