Fluid Flash Layouts
Here’s how to do Fluid Flash layouts quickly without Flex.
Fluid layouts are not new but fhard to come by documentation.
To create a Flash fluid layout, essentially what you do is create a Flash movie that is set to 100% in HTML/SWFObject/XHTML but scaling set to noScale. Then in the flash script you position each element as needed on a resize handler.
This works great for applications built in Flash that will need to scale such as an IDE, a word processor, an image editing programs or programs that might have floating panels and tools.
1) Make your flash movie HTML scaled to the browser:
If you are using deconcept’s excellent SWFObject (be sure to download it) then see this sample for the HTML embedding with js swfobject.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>blipgames.com</title> <script type="text/javascript" src="swfobject.js"></script> <style type="text/css"> /* hide from ie on mac */ html { height: 100%; overflow: hidden; } #flashcontent { height: 100%; } /* end hide */ body { height: 100%; margin: 0; padding: 0; } </style> </head> <body> <div id="flashcontent"> <strong>You need to upgrade your Flash Player</strong> </div> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject("myMovie.swf", "myMovie", "100%", "100%", "8", "#efefef"); so.addParam("scale", "noscale"); so.write("flashcontent"); // ]]> </script> </body> </html>
2) Inside your flash code:
AS2
Stage.align = "TL"; // Top left align the stage Stage.scaleMode = "noScale"; // Set noScale for containing stage.// CREATE A LISTENER OBJECTsizeListener = new Object();// ATTACH THE ON RESIZE EVENT TO THE LISTENERsizeListener.onResize = function() { // In the event call a method to move the items // or, call each item here to be sized movieToBeCentered._x = Stage.width/2; movieToBeCentered._y = Stage.height/2; movieToBeCentered._width = Stage.width * .5; // add other movie clips to position... }; // ADD THE LISTENER Stage.addListener(sizeListener);AS3
package { import flash.display.*; import flash.events.*; import flash.utils.*; public class AppMain extends MovieClip { public function AppMain() { stage.addEventListener(Event.RESIZE,onResize); stage.align = "TL"; // Top left align the stage stage.scaleMode = "noScale"; // items do not stretch to fit }public function onResize(event:Event) { // In the event call a method to move the items // or, call each item here to be sized movieToBeCentered.x = stage.width/2; movieToBeCentered.y = stage.height/2; movieToBeCentered.scaleX = stage.width * .5; // ... etc } } }
This allows you to see easily how you can make a fluid layout in flash that scales with more of an alignment lock rather than the whole movie scaling.
A demo and toolkit will be available soon with an easy class library soon. For now you can go here to get a demo and source from the http://www.tutorio.com/tutorial/liquid-flash-layout site.





Pingback: ferstenfeld.com » Blog Archive » flash
Pingback: Flash Tools » Blog Archive » This might help with the resize of the butterfly icon. — Elmer