AS3 shared library issues with components Monday, August 03, 2009
I'm on Seabrook Island and went for a walk on the beach just after sunset last night. It's a very secluded beach, so there were only a handful of people in the mile or so that I could see up and down the beach. On the return there was a nice surprise in seeing lots of little baby turtles running across the beach to the ocean.
I'd seen this on TV before, but seeing it in person was a real treat.. and damn they move fast. All the ones I saw made it safely to the ocean, but after that?? Who knows.
I'm converting some things over from AS2 to AS3 and hitting some walls. One of the things I'm having trouble with is implementing a runtime shared library in AS3. According to everything I've looked at I have everything set up right, but it jsut doesn't work. I've used shared libraries for many years so it's not a new concept to me, and I've always been able to get the right voodoo mix going to make them work well, but this time it's just not happening.
Here's what I'm doing and what's not working... I've got everything set up as in the old AS2 days with a "library" SWF with all the clips that I want to reuse in there set to export for runtime sharing. I've got SWFs that contain those clips and have them set to import from the shared library. So far so good. All works just fine as long as they're movieclips.
Now..... if I make a component and put it into the shared library and set it to export for runtime sharing things get interesting. If my other SWFs don't have that component set to import from the shared library then the class code for the component in the shared library will replace what is used in the other SWFs and the components will show up. BUT... if the other SWFs have that component set to import from the shared library then the component doesn't show up AT ALL. It's in the shared library but it isn't loaded or displayed by the other SWFs.
I've tried having a "main" SWF that first loads the shared library SWF and then loads each of the other SWFs and have it set the ApplicationDomain.currentDomain for all of them to the same. No help there.
Back in the AS2 days the point of a shared library was to reduce the file size of all the SWFs that use the library. If you had a few dozen or few hundred SWFs that all used the same components and those components were all in the shared library then you were saving the user from downloading those components hundreds of times.. a side benefit was that you could change the code in the component in the shared library and it would be a global change across all of the hundreds of SWFs that used that shared library. It seems that with AS3 I can get the components to use the class code from the shared library (so I can make global code changes), but only if they're fully exported in each of the SWFs (so there's no reduction in file size).
The turtles run fast to the sea, but they don't know what they face.
I should have been more specific with the post above (hey, I was on vacation at the beach.. cut me some slack.. ). The wall I hit was with CS3, and I still haven't gotten beyond it. This might sound odd to some, but not everybody has CS4.. so you sometimes have to develop for the least common denominator.
Now, if you're hitting this issue and have access to CS4.. you have some hope. You can specify an "External Library Path" to a SWC file either in the global Preferences, or in the Publish Settings for each FLA. Jesse has some info on setting up that SWC. After doing that the components show up just fine.
Maybe the least common denominator needs to upgrade to CS4..
Oh, and using "Automatically declare stage instances" really mucks things up.