After a long stretch of 'just coding', it is getting back to making decisions again. I'm trying to spec out the next steps, wondering about the best paths. Ultimately it comes down to, if you could make swfs in C#, what would your 'dream code' look like? How would it interact with library items and timelines? What should the bytecode look like - optimized for speed/size/legibility? Any and all opinions welcome : ).

Plans on Transforming AS/SWF > C#?

I have some swf parsing stuff, I'm not sure how well that will integrate though. A lot of the metadata simply gets discarded when going to swf (interfaces, types, params etc), even when writing C#>swf. I've looked into getting swf7 code to reverse (to C#), it seems somewhat do-able, except there will be a lot of 'object' types and inserted casting if people didn't declare types. I'm not sure if it would be more valuable to reverse right to C#, or plan B...

Plan B

I would like to get a mode where you could insert bytecode and add C# stubs based on a flash file though. If someone has an actionscript class that works, why not use it, eh? Also I'm finding the need to do a lot of stuff manually by adding pushes/actions manually in the support code, but it is a total pain. An automated way to do this is crucial, however it isn't as simple as just adding bytecode as it probably has to integrate with the constant pool etc (that is for code that C# doesn't need to see, things like the extends class, or native swf calls)

How to attachMovieClip, access _width etc.

I'm really debating how to access the flash stuff as well. One idea is just to have an Swf.Native namespace that always compiles to actually internal flash methods. Ideally though it would work more like being able to get a 'DrawingCanvas' or 'AnimationReel', each with it's own properties, even though they both resolve to Movieclip on compile. I guess that still requires a Native call somewhere, but ideally they would be hidden unless making a wrapper class, and even then only used once, somewhere isolated.

Optimized Mode

C# maps everything except virtual dispatch at compile time, so you can really optimize things, where that might be harder in actionscript. I've been doing some tests, and I'm thinking of using arrays everywhere, and then registers for locals. Right now, from the parse, all definitions (namespaces, classes, fields, locals etc) are indexed. Already for overloads it writes out the name and the index, like Meth_22 (actually the top level matching overload index, so virtual dispatch works). So what I was thinking is putting all the methods/fields/props etc in the prototype in array slots. Eg:

cls = function(){}
cls.prototype[0] = "hello";
cls.prototype[1] = function(){ trace(this[0]); }
c1 = new cls();
c1[1]();

Obviously the types (classes, enums, delegates) could all be array indexes of an object stored in a permanent register, as would static methods, constructors, and internal functions like 'extends' (basically anything statically referenced).. Given a low number of static definitions, some of them could even be mapped to permanent registers.

This should be really easy to do, just reordering the indexes and push a number instead of a constant pool. I assume AS has better performance when indexes are sequential, instead of the first one starting at 276, haven't tested though. Then locals could be put in registers (though that will require some work) and everything should be pretty fast (again, haven't tested). It should also be quite a bit smaller, as there is basically no constant pool, and path lookups with always be simply a register/this push, and index, and a get member (instead of the much longer path.path.path lookups). Change a few things and it becomes painfully obfuscated too -- eg: r1:[231][64](this[3]()) becomes even harder to decipher when those numbers are the result of looked up calculations, and then there is still that evil 'eval' ; ).

Todo

Anyway, first the bug free mode. Hopefully by Monday there will be a new version. Right now inheritance/base/this (chaining), virtual dispatch is there, 'using' is almost there as are multiple files/namespaces. Todo before then, events, distinguish between int/long double/float, out/ref params, indexers, and deal with structs. (end of week)

After that, try/catch, attributes, some type reflection (for typeof, as, is), and experiment with optimized mode. Also work on native calls into swf in a type safe way, and a simple demo framework. (one month)

After that, import graphics, sound etc (eg, the Flash 'library' part). (Maybe maybe end of summer, depending on work)

posted on Thursday, July 15, 2004 4:35 PM
Feedback
  • # re: Thoughts on how best to build swfs with C#
    Nik Khilnani
    Posted @ 7/16/2004 11:24 AM
    ill post my reply to ure comment in ure last post here since u addressed my swf > c# question here...

    one use i can see would be generating documentation from a swf file... so this would work for flash 6 and flash 7 swf files

    thats not a solid case tho.. something more interesting is, retriving as code from a swf file and picking if you want it in as 1 or as 2.... good for lost source code... OR converting an as 1 project into as 2 wihtout having to go in and modify all ure code... this would also be used to convert the flash mx 2004 components written in as 2 to as 1... so if you want to use as 1 in flash mx 2004 and use the in built components you could... (oops did i say change mm's components... sorry) for this im asumeing what ive heard/read that both as 1 and as 2 compile to same byte code.... i havent checked if asv 4 supports output to as 1 or as 2...

    another one may be, if you can parse the swf file in a tree..etc.. would could do optimizations on the code that could be written back into the same or new... this is like haveing a program do what ppl do with flasm... obfuscation could be a use.... or if we have a tree we could output a trail of how the program works.... good for projects with multiple developers and less documentation and maintaing large projects... refactoring...

    lemme know if something i said doesnt make sense...

Blog Stats

  • Posts - 121
  • Stories - 1
  • Comments - 1441
  • Trackbacks - 47

.Net Blogs

01101 Blogs

Flash Blogs

Graphics

People