2 Replies Latest reply on Oct 30, 2006 10:51 AM by Newsgroup_User

    local variables?

    j-eggs
      I'm trying to load several movieClips in a loop. Right now, only the last clip in the array will display. It seems like it might be a local vs global variable problem, but I think that I'm declaring all of my variables locally. Does anyone have a good suggestion?

      import flash.geom.Transform;
      import flash.geom.ColorTransform;
      var buildings:Array = new Array();
      buildings[0] = new Array("file://localhost/Desktop/movie1.swf", 0, 0);
      buildings[1] = new Array("file://localhost/Desktop/movie2.swf", 100, 0);
      for (var i:Number = 0; i<buildings.length; i++) {
      var fileName:String = buildings
      [0];
      var xPos:Number = buildings [1];
      var yPos:Number = buildings
      [2];
      trace(fileName);
      var loadListener:Object = new Object();
      var movieClipLoader:MovieClipLoader = new MovieClipLoader();
      var building:MovieClip = createEmptyMovieClip("building", getNextHighestDepth());
      loadListener.onLoadComplete = function(target_mc:MovieClip) {
      target_mc.hitArea = createRectangle(xPos, yPos, 0, false);
      target_mc._x = xPos;
      target_mc._y = yPos;
      var trans:Transform = new Transform(target_mc);
      //trace(trans.colorTransform);
      // (redMultiplier=1, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=0, alphaOffset=0)
      var blueColorTransform:ColorTransform = new ColorTransform(0, 1, 1, 1, 0, 0, 255, 0);
      var blackColorTransform:ColorTransform = new ColorTransform(0, 0, 0, 1, -255, -255, -255, 0);
      var sel:Boolean = false;
      target_mc.onRollOver = function() {
      trans.colorTransform = blueColorTransform;
      };
      target_mc.onRollOut = function() {
      if (!sel) {
      trans.colorTransform = blackColorTransform;
      }
      };
      target_mc.onPress = function() {
      sel = !sel;
      trans.colorTransform = blueColorTransform;
      // trace(trans.colorTransform);
      // (redMultiplier=0, greenMultiplier=1, blueMultiplier=1, alphaMultiplier=1, redOffset=0, greenOffset=0, blueOffset=255, alphaOffset=0)
      };
      };
      movieClipLoader.addListener(loadListener);
      movieClipLoader.loadClip(fileName, building);
      }
      //building.hitArea = createRectangle(300,300,0, false);
      function createRectangle(xPos:Number, yPos:Number, color:Number, vis:Boolean):MovieClip {
      scope = this;
      var depth:Number = scope.getNextHighestDepth();
      var mc:MovieClip = scope.createEmptyMovieClip("mc_"+depth, depth);
      mc.beginFill(color);
      mc.moveTo(xPos, yPos);
      mc.lineTo(xPos, 100+yPos);
      mc.lineTo(100+xPos, 100+yPos);
      mc.lineTo(100+xPos, yPos);
      mc.lineTo(xPos, yPos);
      mc._visible = vis;
      return mc;
      }
        • 1. local variables?
          anonymous thing Level 1
          I think there's a mistake when you access array properties

          for (var i:Number = 0; i<buildings.length; i++) {
          var fileName:String = buildings[i ][0];
          var xPos:Number = buildings[i ][1];
          var yPos:Number = buildings[i ][2];
          }

          and try to generate a new MovieClip name each time :
          createEmptyMovieClip("building"+i+"_mc", getNextHighestDepth()); // just an example

          If it's not the answer I will look more carefully your code...


          ***** sorry for the bad answer; forum strip your and my "[i ]"(without the space)
          • 2. Re: local variables?
            Level 7
            >>var building:MovieClip = createEmptyMovieClip("building",
            >>getNextHighestDepth());

            I think this is your problem - getNextHighestDepth() is not a global
            function. It is a MovieClip method - so for it to do anything, you need to
            give it a clip to get the depth of - as in:

            var building:MovieClip = createEmptyMovieClip("building",
            this.getNextHighestDepth());

            which will get the next highest depth of the clip the function is attached
            to - which I am assuming is root.

            Also, setting _x and _y properties in onLoadComplete is wrong. Set them in
            onLoadInit instead. Just change onLoadComplete to onLoadInit and you should
            be good.



            --
            Dave -
            Head Developer
            www.blurredistinction.com
            Adobe Community Expert
            http://www.adobe.com/communities/experts/