attachMovie doesn’t return a value… in the Twilight Zone

Ok, it must be because I’m down to the wire on this project, but after the 2nd time of having attachMovie not return a value in one of my functions, I just couldn’t take it anymore, and had to solve it.

And I did, MOFO!

…I just don’t understand the results.

My problem:
– attachMovie was not returning a value
– tracing the function call printed the movie clip path in the Output Window
– tracing it with a string in the trace statement printed a NaN in the Output Window; trace(“ref_mc: ” + attachMovie(“MyComponent”, “my_mc”, 0));
– utilizing typeof and instanceof showed undefined in the Output window
– any return value showed undefined

…uh, no, that’s not how attachMovie works. It doesn’t attach a component and then have that component magically work, but not return a value. If I accessed the movie clip, however, it worked. Now, a RAD type of developer would of moved on, simply replacing ref_mc with a pointer to the movie clip’s real name.

Personally, I don’t like shiot breaking and not knowing why. So, after investigation, it turns out that placing a “stop();” in an AS2 constructor/init function will cause the return value to fail. this.stop, using a stop in AS1, or this.stop in AS1 are all fine.

Uh, yeah…ok… sure, that makes tons of sense. :: dar dar dar :: * hits right wrist on chest heavily *

This is important in designing AS2 components because you now place your component’s assets on frame 2 on a non-guided frame. You now have to add a stop to prevent your component from ever reaching that frame since it’s merely there to ensure your component includes all it needs in either travelling to another FLA’s library, or transforming into an SWC. You can place a “stop” command on the timeline on frame 1 if you wish, but most purists don’t believe in any timeline code if possible. Putting it on the constructor/init function is best.

Shared Libraries only work within same version SWF

Ok, one thing to watch out for if your using Shared Libraries in Flash MX 2004 and exporting for 6. Shared SWF’s that are version 6 only work with version 6, and same with version 7 SWF’s only working with version 7 SWF’s. It’s pretty easy to get your wires crossed and wonder why the heck your stuff isn’t working. It’s a little disconcerting too as I’m still learning how the “Make Default” works in relation to Publish Settings.

For example, in Flash MX, if you made some changes to the Publish Settings, clicked OK, and then did Control + J, and clicked “make default”, this would globally make all of your new FLA’s, even after rebooting Flash utilize those settings (pretty sure as I don’t have MX installed here). Used to wreak havoc on people would click “omit trace actions” and weeks later wonder why their SWF was tracing anything. It doesn’t work this way in Flash MX 2004 it seems.

Anyway, just something to watch out for since a lot of us may be still exporting to 6, but Flash MX 2004 seems to default to publishing to 7.

Flash 7 Player Spanks Flash 6 in Speed

Old news, but a new test.

Working on this RIA with this fellow contractor, and we finally decided that the best way sort the multitude of images we were dealing with was simply place all that data we needed about the file in the filename itself, therefore simlyfying the XML. The time it was taking me to create an application in <a href=”http://www.screenweaver.com/”>Screenweaver</a> to actually create the XML files with all data and filepaths intact was pretty long and involved, taking away from my time in actually completing client change requests. Therefore, I’d create a simple image list of files via a smaller scoped Screenweaver app, and then pull in the XML file through Flash. Flash then parses the XML file, strips the filepath, and slices it up via underscore (_) dilmiters into an object of arrays I can use in my code. Each part, such as size, category, and type are in 2 letter abbreviations in the filename. This makes adding new images for the client a snap… you just follow the naming scheme. The lack of error checking in that process as well as the lack of the ability to link some images with others that have common relationships aside, this is so far working pretty good. We were originally afraid, though, about the speed it would take Flash to do something like this on thousands of images.

So, I made a quick app consisting of 6 tests:
– loading in a 100 noded XML file
– loading in a 500 noded XML file
– loading in a 1000 noded XML file
– string parsing the 100 noded XML
– string parsing the 500 noded XML
– string parsing the 1000 noded XML

Then, I called him up, and together we tested the speed. It was crazy. I was using Flash <strike>7.0.16.0</strike> 7.0.14.0 for 3 tests each (below in milliseconds).

loading XML

Dynamic Authortime Symbols

One will admit that Flash, ecspecially currently, is dynamic even before that first SWF is a dream. Keeping things free flowing while developing certainly helps in this volatile climate, but it helps even more if you have some foresight.

Read on to learn about using the Source Property of a Flash Library Symbol in your workflow…