If you are or plan to be working with swf at the format level in .Net, this may be of interest to you... Even though our Xamlon Flash Edition product targets Xaml and C#/IL at the high level, it can still be used to generate swfs at a much lower level. Working at the tag level can be quite powerful (look at Flash after all!), however some things can be a big pain too. Our SwfLib namespace is designed to be a fair amount friendlier than just straight tags, however you still work at essentially the tag level so it is pretty easy to hook up some form of generator.

One of the main differences between straight tags and Xamlon's SwfLib is that we tend to work with .Net classes where possible, rather than lower level tags and objects. For example to make a gradient or bitmap fill, you can work directly with .Net Brushes, rather than setting raw image data. For a static or dynamic text box, you can simply use a .Net Font object. Not only will this find the correct font and style, it also export the appropriate glyphs (used glyphs are automatically detected over all uses of the font, as well as any glyph sets and extra chars that have been set individually).

A second set of helper features have to do with automation. For example, it will automatically scan the tags and figure out what characters need to be exported on which frame. This means you don't need to constantly add characters to a definition table before displaying them. It also avoids the possibility of adding a character twice (or defining after use - and the resulting boom). This has a nice side affect of optimizing the file for streaming. Of course you can still manually specify export frames if you like, which is useful for characters that are 'library only' (eg. to be used by actionscript). So in general, most things that can be derived from tag info do not have to be explicitly stated.

There are also a number of 'helper' classes and methods that aren't actually in the swf spec. For example there is a 'Frame' tag that allows you to work with individual frames as if they actually existed as tags. With this you can simply add a character to a frame, set its duration (in frames) and the compiler will add the appropriate characters, showFrame tags, set depths, and remove items as needed.

The biggest helper method though is probably with bytecode - not just are things like constant pool automatically inferred from the tags, but you can use IL instead of bytecode, meaning you can program in a high level language like C# -- I guess that isn't really a low level feature though : ). Of course if you like pain as much as I seem to, or maybe you just want to make your own bytecode generator, all the action tags are there. For simple event or playhead stuff, going full IL>swf is probably overkill for sure...

Well what is a post without some code! Here is a simple example that does nothing useful, though with a little effort it could probably be reworked to bring us all everlasting world peace...

// All movies have a RootSprite (_root) as their root object
// it holds movie wide properties, as well as holding the root timeline.
RootSprite root = new RootSprite();
// note the .Net Color object here
root.BackgroundColor = Color.Tomato;
// ..and Size object
root.FrameSize = new Size(550, 400);
root.FrameRate = 12;
root.Compressed = true;

// make a shape with a gradient brush   
DefineShape3 def = new DefineShape3();

// define a line style and gradient fill
LineStyle ls0 = new LineStyle(Color.DarkViolet, 4);
LinearGradientBrush lgb = new LinearGradientBrush(
 new Rectangle(30,10,200,30),
 Color.CornflowerBlue,
 Color.FromArgb(80, 0, 0, 30), // alpha fill
 30);

// add the color and start position
StyleChangeRecord scr = new StyleChangeRecord();
scr.LineStyle = ls0;
scr.FillStyle0 = new GradientFill(lgb);
def.Shapes.ShapeRecords.Add(scr);

// add the edges
def.Shapes.ShapeRecords.Add(new StraightEdgeRecord(0, 100 ));
def.Shapes.ShapeRecords.Add(new StraightEdgeRecord(100, 100 ));
def.Shapes.ShapeRecords.Add(new StraightEdgeRecord(100, 0 ));
def.Shapes.ShapeRecords.Add(new StraightEdgeRecord(0, 0 ));
def.Shapes.ShapeRecords.Add(new EndShapeRecord());

// place it on stage
PlaceObject po1 = new PlaceObject(def);
po1.Matrix.Translate(50,80);
root.Frames[0].DisplayList.Add(po1);

// place it again for free : )
PlaceObject po2 = new PlaceObject(def);
po2.Matrix.Translate(60,60);
po2.Matrix.Rotate(-25); // we can do this because it is a .Net Matrix!
root.Frames[0].DisplayList.Add(po2);

 

// **** now lets make some text
// define a font

DefineFont font = new DefineFont(new Font("Courier New", 12, FontStyle.Bold));
font.ExportGlyphs = true;

// create text box
EditText text = new EditText(font);
text.InitialText = "Hello world,\nyou sick puppy!";
text.FontHeight = 40;
text.UseOutlines = true;
text.TextColor = Color.Yellow;
text.Bounds = new RectangleF(10, 10, 300, 800);

// places the textbox on the view area
PlaceObject obj5 = new PlaceObject(text);
obj5.Matrix.Rotate(25);
obj5.Matrix.Translate(150,20);
root.Frames[0].DisplayList.Add(obj5);

// now just write it out using an SwfWriter
SwfWriter w = new SwfWriter();
root.Write(w);
w.WriteToDisk("test.swf");
System.Diagnostics.Process.Start("test.swf");

And here is the resulting swf:

http://blog.debreuil.com/Images/sample.html
   
We are just polishing up the SwfLib part now, so our bits are a fair amount more advanced than the beta on the site, but that will give the general idea anyway. If you want to have a look at a more recent version we could probably send along something before too long, just drop me or anyone else on the Xamlon team a line, or drop a note on the forums : ).

posted on Wednesday, February 02, 2005 6:24 AM
Feedback
  • # RE: Are you using swf at the format level?
    Philippe
    Posted @ 2/2/2005 8:16 AM
    > all the action tags are there.
    Now that's fun ;)

    Is it possible to *read* and existing SWF to rewrite it ?


  • # RE: Are you using swf at the format level?
    Robin Debreuil
    Posted @ 2/2/2005 3:09 PM
    Hey Philippe,

    We currently are only gening swf, though we do more or less have code to parse it -- it just goes into a slightly different format (it is from the old swf>svg translator I had done before). I'm sure we eventually will read swfs too, or if there would be interest, sooner than eventually : ). But at the moment, no, we don't read swfs...

Blog Stats

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

.Net Blogs

01101 Blogs

Flash Blogs

Graphics

People