Jump to content
Search Community

Using DisplayObjectContainer yields error 2012

brianr test
Moderator Tag

Recommended Posts

I'm using SWFLoader to load a swf and want to load it into a container. According to the API Documentation, i can use:

container : DisplayObjectContainer - A DisplayObjectContainer into which the content Sprite should be added immediately.

When I try and do this I get Error #2012: DisplayObjectContainer$ class cannot be instantiated. So I use the import statement as follows:

import flash.display.DisplayObjectContainer;

but still same thing. When I googled the error it came up with info about it being an abstract class and the remedy would be to use

extends DisplayObjectContainer

but I need mine to be

 extends MovieClip

. I tried extending sprite but that threw a frame error, so it needs to be movieclip. What else can I do?

Link to comment
Share on other sites

You just need to set your container property to be a Sprite or MovieClip which themselves are types of DisplayObjectContainers.

 

 

//option 1
//in the Flash IDE create a movie clip symbol on the stage with the instance name of swfHolder

//OR

//option2
//programmatically create a Sprite with code and add it to the stage

var swfHolder:Sprite = new Sprite();
addChild(swfHolder);

var swf:SWFLoader = new SWFLoader("someSwf.swf", {container:swfHolder})
swf.load();

Link to comment
Share on other sites

Hi Carl, thanks for the quick response!

 

Your suggestion is essentially what I've done at this point (option 2). Now that I've removed the DisplayObjectContainer and turned mediaContainer back to a Sprite, it doesn't throw the error any more but still doesn't seem to be adding the loaded swf to the container as when I change the x, y, coords of the container, the swf doesn't move accordingly. Also I put a trace statement after the loader and it shows that mediaContainer has 0 children.

 

public var mediaContainer:Sprite = new Sprite();
...
addChild(mediaContainer);

	public function LoaderMax_subload_parent():void {
		var subloadSWFpath:String = menuXML.slide[slideIndex].mediaPath;
		var swfScale:Number = menuXML.slide[slideIndex].mediaPath.@scale;
		trace("swfScale = " + swfScale);
		_swfLoader = new SWFLoader(subloadSWFpath, 
								   {	container:mediaContainer,
								   		scaleX:swfScale, scaleY:swfScale,
									   	onComplete:_completeHandler});
		_loadHandler();

		trace("mediaContainer children = " + mediaContainer.numChildren);

 

	private function _completeHandler(event:LoaderEvent):void {
		//add the SWFLoader's content to the stage
		addChild(event.target.content);
		setChildIndex(event.target.content,0);
	}

Link to comment
Share on other sites

once your _completeHandler fires, changing the xy of mediaContainer will have no effect on the position of the loaded swf as it will have been placed onto the stage.

 

use either the container property to add your swf to the mediaContainer automatically OR use the _completeHandler to do it.

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

once your _completeHandler fires, changing the xy of mediaContainer will have no effect on the position of the loaded swf as it will have been placed onto the stage.

 

use either the container property to add your swf to the mediaContainer automatically OR use the _completeHandler to do it.

 

Carl, could you eloborate this point with some example, as I am stuck on same issue

 

DisplayObjectContainer(_player.panel).addChild(_clickTrackingElement);

Link to comment
Share on other sites

to place your loaded content into the DisplayObject of your choosing either

 

specify the container property in the loader's constructor

var mySWFLoader:SWFLoader = new SWFLoader("mySwf.swf", {container:myContainer});

or use the onComplete callback to add the content 

var mySWFLoader:SWFLoader = new SWFLoader("mySwf.swf", {onComplete:completeHandler});

function completeHandler(e:LoaderEvent): void {
  myContainer.addChild(e.target.content);
}

If this doesn't help, please provide a simple example so that we can look at your problem in the proper context.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...