I’ve gotten a lot of emails asking about some of my older Flash & Flex integration examples not working. Hopefully this article will describe the same error everyone is getting.
ActionScript 3 is strict. However, Flash CS3 helps Flash developers with a feature that automatically generates code during compilation. Meaning, if you have a MovieClip on the stage called “my_anime”, you won’t have to declare a variable like so:
public var my_anime:MovieClip;
Flash CS3 will automatically write that in the code for you.
If you didn’t have that code, you’ll get a runtime exception. That’s because the timeline is effectively going:
yourMovieClipInstance.my_anime = new MovieClip(); yourMovieClipInstance.addChild(yourMovieClipInstance.my_anime);
Since yourMovieClipInstance’s class doesn’t have a property called “my_anime”, it’ll blow up. For a Flex Developer, this makes sense. Everything exists, and you merely addChild/removeChild or toggle the visible property. In Flash, things may not exist till frame 10. For some animations that have a ton of child MovieClips that you need to talk to, this can be a lot to remember. So, the ADSI feature is nice in that Flash worries about it for you.
Flex has no such feature.Â When you bring in Flash content, you’ll get an exception, and you can’t debug it easily because it was the MovieClip’s timeline who caused the error. When you go to debug, you’ll get the 1 line exception “ReferenceError: Error #1056: Cannot create property” in the call stack, and nothing more… and you’re left wondering, who the heck is creating this thing?
While I agree why Adobe put the ADSI feature in Flash CS3, it works against you when you create content for Flex. Take the pain of writing out all of your MovieClip’s as class member properties, and uncheck ADSI via:
- File > Publish Settings
- Flash tab
- Settings button
- un-check “Automatically declare stage instances”
Good to go funky coma-deena.
Here’s the settings screen:
Here you can see a new animation starts on frame 25. Therefore, if there is no class variable called “box”, you’ll get a runtime exception. In Flash CS3, however, you won’t if you have ADSI checked.
Here, you can see I define the box on line 8; this prevents a runtime exception when you embed the SWF in Flex.