Could Flash autogenerate classes from IDE information at design-time?

UPDATE: Chalk this post up to my own ignorance - Simon Cave has pointed out that you can basically do exactly what I proposed by just exporting a swc and compiling with the FlexSDK. Obviously that has it's own advantages and disadvantages, but for the sake of this benefit I'm probably going to move over to that workflow. Here's the original post anyway....

Here's a "what if" post for any developer who works with the Flash IDE. Something that often bugs me is that when you want to access DisplayObjects which have been placed on the timeline of a MovieClip, you don't know what DisplayObjects are there, or their type. For example, say you have an animation, and nested 3 MovieClips deep in the animation is a "hand" MovieClip. You can access the clip with "throwAnimation.leftArm.hand", but while you are developing you can't be sure that this path actually exists, and you won't know the type of "hand". If you want to call a function in hand, you might end up doing something like: "Hand(throwAnimation.leftArm.hand).closeFist()". It works, but again you don't know while you're typing that "hand" actually is an instance of the Hand class.

One solution might be to create a ThrowAnimation class, an Arm class and a Hand class and set the linkages of each MovieClip in the library. These classes would simply contain public variables for the DisplayObjects they contain. Then you can happily type: "throwAnimation." (hit CTRL-SPACE in Eclipse) and your code editor will give you a drop-down menu showing all the variables of throwAnimation, including leftArm, hit ENTER and then get a list of leftArm's properties, including hand. The only downside is, you have to create 2 more classes just to get autocompletion.

Thinking back to my days doing Visual Basic, I think I remember that it autogenerated some code every time you added a button to the design view. Flash just needs to do the same thing. Think about it - all the information it needs is right there to autogenerate classes which know what DisplayObjects they contain and their type. It can get the instance names from the stage and the type from the Library. Then we happily know while we code that we are accessing DisplayObjects that exist. I think this is basically the same idea behind MXML and XAML - so maybe what we need is a just an XML-driven FLA format in CS5? Any thoughts?


wonderwhy-er said…
One of things that indeed bugs in Flash IDE...

I actually tried to do a small investigation if it is possible to do it trough JSFL extension but JSFL seriously lacks public documentation :(
But I did learn some stuff. Trough JSFL you can get access to "in frame" code and theoretically gather information on methods and variables in MovieClips and autogenerate some class with those. Also you can ask instances for their childes trough JSFL and if I rightly remember then you can get classes names for those too. So add those to autoGenerated classes... Or add those in to "in frame" code as variables before generating class.

Then there is code somewhere that allows you to make Flash IDE load custom classes and provide autocomplete for them. But I am not shore that this thing can do it on runtime... May be you need to do it before or along the load of file(did not found precise information on that).

So almost everything that is needed is there to make on our own. At least it seems so... Tough there are some things that I am not shore about...

For example it seems that there is now way to directly tell something to autoComplete... But it still probably possible trough autoGeneration of classes and code on frames.

Anyways I kind of lacked JSFL documentation and experience to try and do it and over time kind of lost will as it felt as if I was in complete dark with that documentation problems... Part of it was not even from official documentations(which is old before CS3 even last time I checked but seems to be still working more or less) but rather some not well explained examples I dug trough Google... Not a kind of information you depend on...

May be it would be a good idea to make some open source project/initiative with goals to try and achieve that trough JSFL and involve people from Flash community that had their JSFL experience to solve that problem together?
Simon Cave said…
Hey Iain,

Here's how I do it. I think it solves at least part of what you're after. I use FDT - I'm not sure if there's a similar way to do this in Flex Builder.

Keep all your timeline assets in an FLA which is compiled in the IDE and exported as an SWC. I call this assets.fla. In the FLA, assign export classes to all the assets you want to use (e.g. LeftArmView, HandView). Right click the SWC In FDT and "Add to Classpath" in the "Source folder" submenu.

Now, all your exported assets can be instantiated, introspected, code-completed in FDT, like so:

arm = new LeftArmView();;
trace( arm.hand is HandView ); // true

if you export just LeftArmView, FDT will know what it is, and that it has a child DisplayObject called hand. If you export HandView too, FDT will know what hand is and know about all its nested children as well.

As an added bonus, FDT will even create pseudo source files for every exported asset in the SWC.

I highly recommend this workflow - it completely eradicates the anonymity that you're describing.
Iain said…
@Simon - just tried that out on FlashDevelop - that's freakin' awesome!!!! Basically exactly what I was thinking of. I knew lots of people were using this method of publishing, I just didn't know it could that.

Man, I've been living in a cave - no offense ;)

Consider this my new workflow!
Jared said…
@Simon - You can achieve this same thing in Flex in the Actionscript Build Path settings of the project. Under the Library Path tab you can add individual swcs or add a "SWC Folder" to automatically include all contained swcs.

Works best if that folder is outside of src. We put our asset swcs in lib, next to src.

Worked well in our latest project.
Philippe said…
The SWC workflow works great in most "smart" IDEs.

FlashDevelop, like FDT, will generate preudo source files when you look for their definition.

Workflow is described (with tips) here:

Cheers :)