views:

1599

answers:

2

Hi, I have a problem converting SWFLoader.content into a MovieClip instance while following (TheFlashCanon's excellent tutorial) on making a SWF communicate with Flex. The SWF loaded in question is compiled using Flash CS3 (using actionscript 3).

However, when I try to get the content of the SWFLoader and convert it into a MovieClip instance, I always get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert maix::main_maix@49f94ec1 to flash.display.MovieClip. at test1/onLoadMinigameComplete()[/Users/chiyin/Documents/Flex Builder 3/SimpleGirlfriend/src/Main.as:68]

where maix::main_maix@49f94ec1 is an instance of my movie.

What am I doing wrong? The loaded swf plays fine otherwise, and is not denoted as a AVM1Movie.

Update: Found out that the SWF is imported as a Sprite instead of a Movieclip. How do I force the SWFLoader to load the SWF as a Movieclip instead of a Sprite object?

A: 

main_maix looks to be the document class of the swf being loaded in. If so, main_maix should extend MovieClip instead of Sprite:

public class main_maix extends MovieClip

Also, you can always cast classes an object to be able to access it freely (but not a very good practice). You may want to just "cast it as main_maix":

/**
 * Loader finished loading
 * 
 * @param Event Complete event
 * @return void
 */
private function onLoadMinigameComplete(event:Event):void 
{
    // -- either will allow "free access" to methods of main_maix
    var maixAsObject:Object = Object(loader.content);
    var maixAsMaix:main_maix = main_maix(loader.content);
}
Typeoneerror
A: 

I don't know if this is the same for dynamically loaded swfs. But if you're making a movieclip in the Flash Authoring environment, and it only has a single frame. Then you embed that into a Flex application. It will embed as a sprite instead of a Movieclip.

Marc Hughes