Search code examples
flashactionscript-3

Loading an external SWF file into a loader movie and type casting to MovieClip


I am trying to import a SWF file into a custom loader and then treat the loaded SWF file as a MovieClip object. The code for the functionality can be seen below.

public function loadMyMovie(movie:String)
{

    var now:Date = new Date();

    var rnd:String = "?randomize=" + now.time;

    var request:URLRequest = new URLRequest(movie);

    request.data = getObjectURLVariables(this.loaderInfo.parameters)

    var loading:Loader = new Loader();

    loading.load(request);

    loading.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

    function loadComplete(event:Event):void {

        var movie:MovieClip = addChild(loading.content);

        movie.gotoAndStop(0);

    }

}

When I do this I get the following error.

Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip.


Solution

  • The answer is that the SWF file I was attempting to import was AS2, so it was being imported as a AVM1Movie object. Need to speak with the developer who produced the SWF.