title: How to access variable from nested function
body: <p>I want to pass the "galleryArr.length * 400;"out side the function onGalleryLoaded so I made the function "initmyWidth" and called it from outside the functions with "trace(initmyWidth());" but it gets an error "Call to a possibly undefined method initmyWidth"
  is there a way to pass it one more level outside the functions?</p>
  
  <pre><code>function onGalleryLoaded(e:Event):void
      {
  
          var imageX:int = 0;
          var imageY:int = 0;
  
  
          for each (var image:Sprite in galleryArr)
          {
  
              var my_mc:MovieClip = new MovieClip();
  
              my_mc.addChild(image);
  
  
              parent_mc.addChild(my_mc);
  
              my_mc.width = 400;
              my_mc.height = 400;
              my_mc.x -=  parent_mc.width;
              my_mc.y = imageY;
  
              function initmyWidth():Number
              {
                  var myWidth:Number = galleryArr.length * 400;
                  return myWidth;
              }
  
  
              imageX -=  my_mc.width + PADDING_X;
              if ( (imageX+my_mc.width) &gt; stage.stageWidth )
              {
                  imageX = parent_mc.width;
                  imageY = 0;
              }
  
          }
      }
  
      trace(initmyWidth());
  </code></pre>