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?
Best Answer
main_maix
looks to be the document class of the swf being loaded in. If so, main_maix should extendMovieClip
instead ofSprite
: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":