This blog has moved to a new location! http://iqandreas.github.com/

Wednesday, September 9, 2009

Error: Error #2069: The Loader class does not implement this method.

Error: Error #2069: The Loader class does not implement this method.
at Error$/throwError()
at flash.display::Loader/addChild()
at Main/onXMLComplete()[C:\Documents and Settings\Andreas\Desktop\temp\menu_8_sept\Main.as: 116]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Following this error number leads to a simple line:
ActionScript Code:
var imgLoader:Loader = new Loader();
var preloader:Preloader = new Preloader(); //Just a little custom preloader class that says "Image Loading"
imgLoader.addChild(new Preloader()); //ERROR #2069



At first thought, this should be possible. Checking the language reference, the Loader class extends "DisplayObjectContainer", so it should indeed have that function.

In fact, all of the following functions will give an error message:
  • addChild()
  • addChildAt()
  • removeChild()
  • removeChildAt()
  • setChildIndex()


The answer is hidden away in small print inside of the Language Reference:
Quote:
The Loader class overrides the following methods that it inherits, because a Loader object can only have one child display object—the display object that it loads. Calling the following methods throws an exception: addChild(), addChildAt(), removeChild(), removeChildAt(), and setChildIndex(). To remove a loaded display object, you must remove the Loader object from its parent DisplayObjectContainer child array.
So, basically, because the Loader class can only ever contain one item, you are not allowed to run functions on the loader class that change how many items are inside of the loader.

As usual, the ActionScript 3.0 Language Reference is your best friend.

No comments:

Post a Comment