title: Actionscript 3: Access movieclips from array with for-loop
body: <p>I am having some trouble with accessing the movieclips I've added as childs. From what I've read, a way to solve this is to add every new movieclip to an array, and then loop through this array when I want to change something about all the movieclips.</p>
  
  <p>In my case I want to scale them.</p>
  
  <p>This is how I've tried to implement this function:</p>
  
  <pre><code>package 
  {
  import flash.display.MovieClip;
  import flash.utils.Dictionary;
  import flash.events.MouseEvent;
  
  import Airport;
  
  public class Main extends Sprite
  {
      public var tile:MovieClip
  
      public var bg_image:Sprite;
      public var airport:Airport;
  
      public static var airportDict:Dictionary = new Dictionary();
      public static var collectedAirportArray:Array = new Array();
  
  
      public function Main()
      {
          addEventListener(Event.ADDED_TO_STAGE, init);
      }
  
      public function init(e:Event):void
      {
          removeEventListener(Event.ADDED_TO_STAGE, init);
  
                      // airportDict is being filled up here.. but that's not really relevant for my problem
  
          bg_image = new Image();
          addChild(bg_image);
  
          bg_image.addEventListener(MouseEvent.CLICK, testfunction);
  
          for (var k:Object in airportDict)
          {
              var airport:Airport = new Airport(k,airportDict[k]["x"], airportDict[k]["y"]);
              collectedAirportArray.push(collectedAirportArray);
              bg_image.addChild(airport);
          }
      }
  
      private function testfunction(evt:MouseEvent):void
      {
          for each (tile in collectedAirportArray)
          {
              tile.scaleY = 2 * tile.scaleY;
          }
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This give me the error message <code>TypeError: Error #1034: Type Coercion failed: cannot convert []@30977eb1 to flash.display.MovieClip.
      at Main/testfunction()</code> when clicking on the <code>bg_image</code></p>