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

Actually, I already know the answer. :stuck_out_tongue: The main reason I’m posting it here is for Google searchers, and if I copy and paste the post into my blog, my ActionScript code gets formatted all pretty, when all I have to do is add “as” tags here. :slight_smile:

[INDENT]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 emp\menu_8_sept\Main.as:116]*
  • at flash.events::EventDispatcher/dispatchEventFunction()*
  • at flash.events::EventDispatcher/dispatchEvent()*
  • at flash.net::URLLoader/onComplete()*
    [/INDENT]
    Following this error number leads to a simple line:
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 [U]Loader[/U] class extends "[URL=“http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/DisplayObjectContainer.html”][U]DisplayObjectContainer[/U]", so it should indeed have that function.

In fact, all of the following functions will give an error message:

[LIST]
[]addChild()
[
]addChildAt()
[]removeChild()
[
]removeChildAt()
[*]setChildIndex()
[/LIST]

The answer is hidden away in small print inside of the Language Reference:

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 [U]ActionScript 3.0 Language Reference[/U] is your best friend. :book:

Posted into blog at: