2 Replies Latest reply on Nov 4, 2006 9:29 PM by FrankvZ

    Map problem

    FrankvZ Level 1
      I am trying to make a map game where you get the name of an area and have to click on the correct area. I have programming experience but am fairly new to Actionscript. At this point I want every area to change color when i click on it. I have now 3 areas (MovieClips) named area0, area1 and area2 and the following code:

      import flash.geom.ColorTransform;
      import flash.geom.Transform;
      for(var i = 0; i < 3; i++){
      // Loop through every area.
      var thisArea = this['area'+i];
      // Do something if the area is clicked.
      thisArea.onRelease = function(){
      trace("Clicked:"+this._name);
      var colorTrans:ColorTransform = new ColorTransform();
      var trans:Transform = new Transform(thisArea);
      colorTrans.rgb = 0x1AFF00;
      trans.colorTransform = colorTrans;
      }
      }

      However, this only changes the color of the last area in the for-loop (area2). I don't understand why, as according to the documentation variables within functions should be local. Any help would be greately appreciated.
      Frank