7 Replies Latest reply: Mar 30, 2011 2:39 PM by barpos RSS

    What's wrong with my code?

    barpos Community Member

      Initially, I had a background image on my stage.  I later took it off and added the following code on frame 1.  When I do that, the rest of my AS3 code does not work as intended (my display objects no longer get resized based on browser size), and I get the compiler error: TypeError: Error #1009: Cannot access a property or method of a null object reference.  No error rendered when testing it via Publish-Preview, but display objects won't resize as well.  Any ideas what it is in the code below that you suspect might cause pain and suffering?

       

      // load the background image
      var pixLoader:Loader = new Loader();
      pixLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, pixLoadComplete);
      pixLoader.load(new URLRequest("MicrosoftBuilding.jpg"));

       

      function pixLoadComplete(event:Event):void
      {
          // grab the fully loaded image
          var pixData:BitmapData = event.target.content.bitmapData;
          buildingPix = new Bitmap(pixData);
          buildingPix.name = "Background Image";
          addChildAt(buildingPix,0);
      }