views:

386

answers:

3

I have a main.swf and inside it is just a plain container movieclip. Using the Loader function I load an external swf called content.swf inside that container. Container.swf has a button inside it. Now when external swf is loaded in container mc which is on the main.swf stage, I want to move to another frame by clicking the button of the loaded external swf. If I try to control it from the main timeline I get error saying

cannot convert flash.display::Loader@117e7041 to flash.display.MovieClip.

If I try to control it from the external swf I can trace the click on the button but timeline doesn't move to the wanted frame.

+2  A: 

From the error message it seems that you are trying to cast a loader into a movie clip. Use the loader.content property instead.

var mc:MovieClip = loader.content as MovieClip;
//do whatever you want with mc
Amarghosh
But remember:"SWF files written in ActionScript 1.0 or 2.0, which are loaded as AVM1Movie objects, cannot cross-script SWF files written in ActionScript 3.0, which are loaded as Sprite or MovieClip objects. You can use the LocalConnection class to have these files communicate with each other. "
Konrad
A: 

I did it like this:

var loaderPath:URLRequest = new URLRequest("content.swf");
var loader:Loader = new Loader();
loader.load(loaderPath);
var mc:MovieClip = loader.content as MovieClip;
container.addChild(mc);

and after this I receive this error:

TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/addChild() at index_fla::MainTimeline/frame1()

Zlatiborac
A: 

Make sure you're using event handlers as shown here because in your case loader.content has not loaded 'content.swf' yet when you try to add it to your container.

Also it is preferable to cast like this:

var mc:MovieClip = MovieClip(loader.content);

For the simple reason that 'as' won't throw you an error is the object you're trying to cast is null or can't be casted.

YC