Build a Fluid Website Layout
Jul 3rd in Web Design
by Makzan
A fluid web layout uses 100% width (and height) of the browser, floating all the contained elements into certain positions. This is opposed to fix-width layout where contents remain fixed no matter what the browser size is.
This technique is popular in HTML/CSS websites, but this tut will show you how to create a similar fluid layout effect in Flash. Every element will reposition itself with ease animation when the browser resizes.
My name is Makzan. I live in Hong Kong, China. I have been a flash developer for 10 years. I enjoy Web Designing and Flash developing. Recently I fall in love with flash/iPhone multiplayer game developing with socket server. You can follow me on Twitter: @makzan or visit my portfolio at FlashDen
Introduction
During the following steps we'll create ActionScript 3 classes which make our flash website fluid. All our display symbols will retain their alignment when the Flash is resized.
The ActionScript classes created in this tutorial can be easily reused in different projects.
Step 1: Background Information of Fluid Layout
As shown in the image below, all the elements which float according to the browser size will be referred to as "fluid objects".
Step 2: Fluid Object Coordinates
Each fluid object will contain alignment parameters. The parameters store the x, y, x offset, y offset value of the object to indicate how it aligns.
Assigning x and y to 0 will make the fluid object align to the top left corner. Assigning x and y to 1 will make the fluid object align to the bottom right corner. Therefore, assignign x and y value between 0 and 1 will float the object at a percentage of the width and height of the browser.
The offset X and Y offset the position of the fluid objects while they align. Offsetting useful when positioning an object whose alignment point is not at the center. The offset is also useful for making margins on the alignment.
Step 3: Create a Directory to Store the Classes
Create a directory called "FluidLayout" in the working directory. This directory will store all classes which relate to the fluid layout classes.
It's a good habit to put the ActionScript class files in directories by category. For example, fluid layout classes will be placed in the "FluidLayout" folder in this case.
Please note that all the directory names, file names and codes are case sensitive.
Step 4: New ActionScript File (FluidObject.as)
Open a new ActionScript file named "FluidObject.as". Save this ActionScript file into the "FluidLayout" directory.
The class FluidObject will store the alignment parameters of the symbols and reposition the symbols when the browser resizes.
Step 5: The Class Skeleton
Let's start coding the FluidObject.as now.
package FluidLayout {
/* Add import classes here */
public class FluidObject {
/* Declare instance variables here */
/* Constructor of the class */
public function FluidObject(target:DisplayObject,paramObj:Object)
{
}
/* Function that repositions the monitored object */
protected function reposition():void
{
}
/* Function that is called when the RESIZE event is fired */
protected function onStageResize(e):void
{
}
}
}
Step 6: Importing Required Classes
Add the following code where you see: /* Add import classes here */
/* class needed on resize Event */
import flash.events.Event;
/* classes needed for MovieClip and DisplayObject */
import flash.display.*;
Step 7: Declaring Instance Variables
There are three instance variables for this class:
- "_param" will store the alignment parameters.
- "_target" will point to the monitored symbol.
- "_stage" is a copy instance of the flash stage.
There is also a setter for "_param" to enable changing of the alignment parameters. Add the following code where you see: /* Declare instance variables here */
/* alignment parameters */
protected var _param:Object;
/* target object to be monitored */
protected var _target:DisplayObject;
/* stage instance of the flash document */
protected var _stage:Stage;
/* Setter for the alignment param */
public function set param(value:Object):void {
_param = value;
this.reposition();
}
Step 8: Implementing the Constructor
The constructor will initialize the target monitored symbol and store the given alignment parameters.
/* Constructor of the class */
public function FluidObject(target:DisplayObject,paramObj:Object)
{
/* Assign the instance variables */
_target = target;
_param = paramObj;
_stage = target.stage;
/* add event handler for stage resize */
_stage.addEventListener(Event.RESIZE, onStageResize);
/* reposition the object with the alignment setting applied*/
this.reposition();
}
Step 9: Implementing the Function: reposition()
The repositioning function is in charge of calculating the new x/y position of the monitored fluid object.
/* Function that reposition the monitored object */
protected function reposition():void
{
/* get the current width and height of the flash document */
var stageW = _stage.stageWidth;
var stageH = _stage.stageHeight;
/* update the x and y value of the monitored object */
_target.x = (stageW * _param.x) + _param.offsetX;
_target.y = (stageH * _param.y) + _param.offsetY;
}
Step 10: Implementing the Function: onStageResize
The onStageResize function is an event handler which is called when the browser resizes.
/* Function that is called when the RESIZE event is fired */
protected function onStageResize(e):void
{
/* reposition the target */
this.reposition();
}
Step 11: The Completed Class: FluidObject.as
The finished class FluidObject is finished in this step.
package FluidLayout {
/* class needed on resize Event */
import flash.events.Event;
/* classes needed for MovieClip and DisplayObject */
import flash.display.*;
public class FluidObject {
/* alignment parameters */
protected var _param:Object;
/* target object to be monitored */
protected var _target:DisplayObject;
/* stage instance of the flash document */
protected var _stage:Stage;
/* Setter for the alignment param */
public function set param(value:Object):void {
_param=value;
this.reposition();
}
/* Constructor of the class */
public function FluidObject(target:DisplayObject,paramObj:Object)
{
/* Assign the instance variables */
_target = target;
_param = paramObj;
_stage = target.stage;
/* add event handler for stage resize */
_stage.addEventListener(Event.RESIZE, onStageResize);
/* reposition the object with the alignment setting applied*/
this.reposition();
}
/* Function that repositions the monitored object */
protected function reposition():void
{
/* get the current width and height of the flash document */
var stageW = _stage.stageWidth;
var stageH = _stage.stageHeight;
/* update the x and y value of the monitored object */
_target.x = (stageW * _param.x) + _param.offsetX;
_target.y = (stageH * _param.y) + _param.offsetY;
}
/* Function that is called when the RESIZE event is fired */
protected function onStageResize(e):void
{
/* reposition the target */
this.reposition();
}
}
}
Step 12: Time to Create a Flash File
Begin a new Flash Document with ActionScript 3.0 supported and call it "website.fla". Then set the Document class as "Website".
If a dialog box pops up with the message: "A definition for the document class could not be found in the classpath,..." just click "OK" to bypass it. We're going to create that class after drawing the graphic symbols.
The background image will be dark in this tutorial (I've put together my own space-like image using Photoshop). Therefore the background color of the flash document needs to set to black. Click Modify > Document to open the Document Properties dialog and change the background color.
Step 13: Draw the Title Symbol
There will be 5 flash symbols on the stage:
- background
- title
- menu
- middle content
- footer
Let's make the title first. The aim of this tutorial is to create floating symbols in the fluid layout rather then creating fancy website components. The symbols will only contain a text field indicating the purpose only.
For the title symbol, there's a semi-transparent background. In order to fit different widths of the browser, the width of the background need to be large enough.
After having finished drawing the symbol, click Modify > Convert to Symbol (F8). Click the "Advanced" button to show detailed settings for the symbol.
Click "Export for ActionScript" to enable the ActionScript to access this symbol. Then find the "Class" field in the dialog and set the value to "Title" for the title symbol. This means that we've assigned a new Class called "Title" to this symbol. We can use this symbol later in the ActionScript.
Remember to name your symbol for easy recognition before you click OK. If a dialog box pops up with the message "A definition for this class could not be found in the classpath,..." again, just click "OK" to bypass it. Since we'll not add any behavior to the symbol, we'll let Flash create an empty class for us.
Step 14: Draw the Other Symbols
Delete the "title" symbol instance on stage because it will be created by ActionScript later.
We'll use the same method to draw "background", "menu", "middle content" and "footer". The class name of these symbols will be Background, Menu, Middle and Footer accordingly.
The background image can be downloaded from the source files. Other symbols are text-field only.
Step 15: Code the Document Class ActionScript
Create an ActionScript file and named as "Website.as"; this class file should be saved in the same directory as the website.fla file.
This class must also share the same name as that set in the Document Class (refer to Step 12). For example, the Document Class "Website" refers to "Website.as" in the same directory. This ActionScript class will be loaded right after the flash is loaded.
Here is the skeleton of the Document Class:
package {
import flash.display.*;
import FluidLayout.*;
public class Website extends MovieClip{
public function Website()
{
}
}
}
Step 16: Implementing the Constructor
package {
import flash.display.*;
import FluidLayout.*;
public class Website extends MovieClip{
public function Website()
{
/* Set the Scale Mode of the Stage */
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
/* Add the symbols to stage */
var bg = new Background();
addChild(bg);
var title = new Title();
addChild(title);
var menu = new Menu();
addChild(menu);
var middle = new Middle();
addChild(middle);
var footer = new Footer();
addChild(footer);
/* Apply the alignment to the background */
var bgParam = {
x:0,
y:0,
offsetX: 0,
offsetY: 0
}
new FluidObject(bg,bgParam);
/* Apply the alignment to the title */
var titleParam = {
x:0,
y:0,
offsetX:0,
offsetY:0
}
new FluidObject(title,titleParam);
/* Apply the alignment to the menu */
var menuParam = {
x:1,
y:0,
offsetX: -menu.width - 20,
offsetY: 20
}
new FluidObject(menu,menuParam);
/* Apply the alignment to the content */
var middleParam = {
x:0.5,
y:0.5,
offsetX: -middle.width/2,
offsetY: -middle.height/2
}
new FluidObject(middle,middleParam);
/* Apply the alignment to the footer */
var footerParam = {
x:1,
y:1,
offsetX: -footer.width - 10,
offsetY: -footer.height -10
}
new FluidObject(footer,footerParam);
}
}
}
Step 17: Ensure All Assets are Ready
Open website.fla in Flash and check again before texting the movie.
There's no need to place the symbols on the stage because the Website.as will create symbol instances from library by using their class names. The linkage class names of the symbols needs to be correct in order for the script to use them. The linkage class name can be checked in the library panel.
Step 18: Ready to View the Result
Click Control > Text Movie or Ctrl(Cmd) + Enter to test the flash website.
Try resizing the window and check if all objects are repositioning to the correct alignment.
Step 19: Further Work
Each FluidObject now needs to have specific x,y,offsetX and offsetY property values. A new Class will be created in the coming steps to simplify the future code when adding new fluid objects.
Step 20: SimpleFluidObject Class
Open a new ActionScript file named "SimpleFluidObject.as". Save this file inside the "FluidLayout" directory because this is part of the FluidLayout package.
This file extends FluidObject class so that it will provides simple alignment by using names like TOP, MIDDLE, BOTTOM_RIGHT instead of specifying the x,y properties.
Here is the skeleton of the class:
package FluidLayout {
import flash.events.Event;
import flash.display.*;
public class SimpleFluidObject extends FluidObject{
public function SimpleFluidObject(target:DisplayObject,paramObj:Object)
{
}
}
}
Step 21: Implementing the Constructor
package FluidLayout {
import flash.events.Event;
import flash.display.*;
public class SimpleFluidObject extends FluidObject{
public function SimpleFluidObject(target:DisplayObject,paramObj:Object)
{
/* Tell parent class to init the constructor */
super(target,paramObj);
/* assign alignment and margin value by the constructor parameters */
var alignment = paramObj.alignment;
var margin = paramObj.margin;
/* Preset the alignment and margin value if need */
if (alignment == undefined) alignment = "MIDDLE";
if (margin == undefined) margin = 0;
/* convert the alignment (eg. "TOP", "BOTTOM_RIGHT") to x, y, offsetX and offsetY */
var params = new Object();
switch (alignment){
case "TOP_LEFT":
params = {
x:0,
y:0,
offsetX: margin,
offsetY: margin
};
break;
case "TOP":
params = {
x:.5,
y:0,
offsetX: -target.width/2,
offsetY: margin
};
break;
case "TOP_RIGHT":
params = {
x:1,
y:0,
offsetX: -target.width - margin,
offsetY: margin
};
break;
case "LEFT":
params = {
x:0,
y:.5,
offsetX: margin,
offsetY: -target.height/2
};
break;
case "MIDDLE":
params = {
x:.5,
y:.5,
offsetX: -target.width/2 - margin/2,
offsetY: -target.height/2 - margin/2
};
break;
case "RIGHT":
params = {
x:1,
y:.5,
offsetX: -target.width - margin,
offsetY: -target.height/2
};
break;
case "BOTTOM_LEFT":
params = {
x:0,
y:1,
offsetX: margin,
offsetY: -target.height - margin
};
break;
case "BOTTOM":
params = {
x:.5,
y:1,
offsetX: -target.width/2,
offsetY: -target.height - margin
};
break;
case "BOTTOM_RIGHT":
params = {
x:1,
y:1,
offsetX: -target.width - margin,
offsetY: -target.height - margin
};
break;
}
_param = params;
/* reposition the fluid object to the right position */
this.reposition();
}
}
}
Step 22: New Usage of the Fluid Objects
Refer to the Website.as file and try using the new alignment method to align the fluid objects.
The Old Method to apply alignment to Title:
/* Apply the alignment to the title */
var titleParam = {
x:0,
y:0,
offsetX:0,
offsetY:0
}
new FluidObject(title,titleParam);
The New Method to apply alignment to Title:
var titleParam = {
alignment: "TOP_LEFT",
margin: 0
}
new SimpleFluidObject(title,titleParam);
Available alignments:
- TOP_LEFT, TOP, TOP_RIGHT
- LEFT, MIDDLE, RIGHT
- BOTTOM_LEFT, BOTTOM, BOTTOM_RIGHT
Step 23: The Published HTML
Now the fluid alignment works on the "Test Movie" in Flash IDE, but there is one key point to make this work on browser.
Open website.fla. Go to File > Publish Settings and ensure HTML is enabled. Click the HTML tab and change the dimension to "Percent". Ensure the percent is set to 100 on both width and height.
Click "Publish" to publish the website as "website.swf" and "website.html" files.
Now open the "website.html" file with your favorite text editor and add the following code in the header. Adding the code right after the </title> tag would be a good choice.
These CSS styles eliminate the gap between the top left side of the HTML and the SWF file.
<style>
body{
margin:0;
padding:0;
}
</style>
Step 24: Advanced Technique: Adding Easing
An easing effect can be applied when the browser resizes so that the objects will move to the correct position with an ease out effect.
Open "FluidObject.as". Add the following lines after "import flash.display.*;". These lines will import the tweening animation class to give the code ability to ease the objects.
/* classes needed for Easing Animation */
import fl.transitions.Tween;
import fl.transitions.easing.*;
Then find the following lines in the "FluidObject.as" file. They are within the "reposition" function.
_target.x=stageW*_param.x+_param.offsetX;
_target.y=stageH*_param.y+_param.offsetY;
Replace them with the following code:
/* set the duration of the easing animation (seconds) */
var duration = 0.5;
/* declare the new X/Y value */
var newX = _target.x;
var newY = _target.y;
/* calculate the new X value based on the stage Width */
if (_param.x != undefined){
newX = (stageW * _param.x) + _param.offsetX;
}
/* calculate the new Y value based on the stage Height */
if (_param.y != undefined){
newY = (stageH * _param.y) + _param.offsetY;
}
/* Tell flash to tween the target object to the new X/Y position */
new Tween(_target, "x",Strong.easeOut,_target.x,newX,duration,true);
new Tween(_target, "y",Strong.easeOut,_target.y,newY,duration,true);
Test the movie, the objects will be easing when the browser resizes (see example below).
Conclusion
We've just created two classes which are in charge of the floating fluid objects. We also created an example to align different objects on stage by using the classes. This example is only a sample case; you can use your imagination to play with the alignments. For example, a symbol may be interactive and its alignment may change from top to bottom when the user clicks on it.
The file structure should be the same as below after you finish this tutorial. Specifically, the FluidObject.as and SimpleFluidObject.as should be in the "FluidLayout" directory in order to work.
Enjoy the Fluid Layout!
User Comments
( ADD YOURS )xun July 3rd
this is awesome! i wanted this tutorial for years back. nice one.
( )FMCR July 3rd
Awesome!! Same here, looking for this a way long time =D
( )jason Kempshall July 5th
Me also! thank you very much!
Márcio Toledo August 3rd
And me too… I’m still trying to move from ACS2 to ACS3 and thought fluid flash layouts were impossible lol.
Awesome! Thank you for the great tut ^^
André July 3rd
Hey, very nice work!! congratulations…
This is very usefull and very well coded
( )Jônatan Fróes July 3rd
WOW!
( )Thanks a lot!
Jay July 3rd
Neat, I kinda did the same thing with my site (inspired by envato) using Flex which makes it easier. I like seeing the actionscript behind the tags though; thanks!
( )Dario Gutierrez July 3rd
Chido!! I use a similar technique for this website http://eventoseuforia.com/flash-index.html. Good tutorial and very explained.
( )azbeen July 3rd
really helpfull thanks and easy to understand.
( )Radu July 3rd
This is not the easiest way to create it.
Also you have to set the calling of setFluid (or whatever…) in the constructor.
This is what I get when I try your demo : http://tinyurl.com/lz6pdb
( )Ian July 3rd
Yeh I get this too… it needs an Event.ADDED_TO_STAGE to initialise the positions for the first load.
( )Erick July 3rd
This is what upsets me. You guys are getting paid to write the tutorial, so do it right, b/c after taking 1-2 hours for your tutorial, it ends up not working, and some here are new to AS# and might not now which event class to use.
jason Kempshall July 5th
Hmmmmmm….too true!
jasc August 24th
HOw I do the Event.ADDED_TO_STAGE to fix that problem?
K July 16th
I don’t know what you guys are talking about. I followed the tutorial and don’t have any problems with it.
( )Erick July 18th
I am sorry. I take back my comment. The Tutorial does work. I think this was one of the most instructional tutorials I could use. I loved it. Sorry, and thank you.
Benjamin Reid July 3rd
Thumbs up for the Museo font is all I can say!
( )MSFX July 7th
Totally, loving the presentation style
( )Jason Pollock July 3rd
Fantastic tutorial! I’m relatively new at Actionscript 3.0 so I’m learning as I go. A question I have is if there a way to prevent or halt someone from shrinking the browser window too far, so that the page elements will NOT overlap each other?
If anyone has any ideas, I’d love to hear about them!
Can’t wait to see more tutorials like this.
( )Jesse Kivivuori July 3rd
Oh damn! This I can call a tutorial! Thanks for this.
( )Eric July 3rd
When AS3 came out I was like “oh crap, I finally mastered this with AS2″. Now with this Tutorial I can now finally attempt AS3 coding. Thanks for this.
Is it easy to do animation now with this AS3 fluid web site?
( )JW July 3rd
I just keep getting vertical and horizontal scrollbars. With Windows and Mac, Firefox/IE/Opera and in different resolutions. Very odd, but to me it doesn’t seem to work as it should be.
( )Piotrek July 4th
Me too.
( )daniel July 3rd
nice however this type of true-fit have more space for improvement.
( )hobofan July 4th
Thanks!
Have been waiting for this for a long time
( )Jaime July 4th
You did an excellent job, worked flawlessly; as a flash deseloper myself I can say this is not for newbies who at least should research and practice a little bit on the basics of as3 programming, first to make sense of the tutorial and stop being frustrated at the first roadblock and second to apply what they have learned to their own vision.
( )Diego SA July 4th
I’ll have to read it calmly. The way the screen stop resizing when elements touch the other side of the screen is something I always wanted to know how to do. Useful tutorial! Thanks!
( )james July 5th
cool!
( )sunjester July 5th
its really nice, but not scalable. there isnt much content to see how it would work with articles, paging systems, shopping carts, etc.
( )von brian July 5th
this is neat and all but as you make the browser smaller, it keeps on resizing.
( )i think it should stop resizing at some point(800×600 for example or smaller)
Avangelist July 6th
I like the way this tutorial is structured, but I don’t understand how to manage the classes file from it. It suggests to set the classes into a seperate folder so that you can re-use them. Makes sense to me.
However I don’t understand where I tell my main file where to find those classes I.E the FluidLayout.as file.
Furthermore it says to put the Website.as class in the same folder. Same folder as what? As the FLA or as the other classes? Does it have to be in that folder, or could it been in a seperate classes folder in a totally different location?
If I can get the answer to that, I can get past step 18 because at the moment I just got a black box with no elements on it but no errors in the console.
( )André July 6th
Where to put the .as files??
First of all you need to understand the packages, the packages are packs of classes, in the flash they are separated by dots, in the system folder are separatted by folders, for example, if you have a package test.mypack, the class of this package should be saved in a folder “test/mypack” wich must be created in the same folder of the .fla file, so if the .fla is in c:/myflashapp for example, the class wich the package is test.mypack should be saved at c:/myflashapp/test/mypack/MyClass.as
If the class have no package ( package { ) the class should be saved in the same folder of the .fla file.
Also you can define a classpath for reusable classes, hit F1 in flash to open the help and search how to set a classpath, so you can store your classes there always respecting the packages with the folders.
( )Avangelist July 7th
Thanks André, I understood that part. So is this:
# import flash.display.*;
# import FluidLayout.*;
importing those files and if so shouldn’t it be something more like:
import rootdir.classdir.FluidLayout.*;
?
I still don’t get any errors, and just a blank stage, so something isn’t quite joining the dots to add the mc’s to the stage.
André July 7th
Note, import is very different of include, and in AS3 the include doesnt use the # anymore.
“import rootdir.classdir.FluidLayout.*;”
it´s wront, the right is:
import FluidLayout.*;
Note that the FluidLayout folder must be at the same folder of the .fla
Latter i will explain it better for you
Preston July 6th
How to be as Action Script 2.0?
( )André July 7th
Stage.onResize=function(){
//here the code when resize…
}
But AS 2.0 is past, better you learn the 3.0 wich is much faster, usefull and easyer!!
( )WhateverMan July 10th
Easier my butt.
André July 10th
The king of comment we dont need here!!
But this kind of person will always heve anywhere
Hugo November 25th
I don’t think as3 is easier than as2
Evelyn July 7th
Good job! Nice work! Kind of complicated for new beginners but I will try to do.
( )André July 7th
There is a known bug in firefox:
When you use the contents 100% x 100%, with margin set to 0 and overflow of the body set to hidden, when you open a new tab in firefox and the tabs bar show up, the area of the contents get smaller, but the Event.RESISE isnt fired.
To work thought this problem, you may use 1px of border-top in your body, like the CSS:
body{
margin:1px 0 0 0;
width:100%;
height:100%;
overflow:hidden;
}
An example of this bug can be viewed in this website:
http://new.reebokclub.com.br/
Just open only this website in firefox, them open a new tab in the same browser, note the contents of the bottom in the page will be hidden.
That´s not a flash bug or bad coding, its really a firefox bug
( )André July 7th
Almost forgetting
The same happens if you open directly a .swf in the browser
( )Alexander July 7th
Can i apply this into a Flex 3 Project?
Excellent tutorial!
Regards.
( )G0D July 7th
My skills just got OWN3D by this tutorial, excellent post…keep it up…
( )Radoslav July 8th
too much coding I guess. I know better and faster way of doing it
( )Vegas September 4th
then share
( )Flash Framer July 9th
This is a great intro to working with scalable content in Flash. Thanks!
( )Mário Santos July 9th
Nice! Very Nice.
Is response to two comments here:
Alexander: Flex 3 has native layout constraints, you can setup horizontalCenter=0;, verticalCenter=0; to center things, and left,right,top,bottom elements to set the position on any visual component and main application.
Radoslav: So… this is one of the many ways to setup the layout elements.
Congrats for the tut.
( )André July 9th
In step 2, a nice way to set the offset is getting the bounds of the object, by using the function getBounds, it will return a Rectangle object wich have the x, y, width and height of the offset, the x represents where is the top_left of the object relative to the registration point, the width and height represents the width and height of the object, for example, if you have a rectangle with 100 of width and 50 of height, and it´s registration point is exactly in the middle, so the getBounds(myObject) will return an Rectangle Object with the following properties: {x:-50,y:-25,width:100,height:50}.
It works with any kind of DisplayObject
Another good thing to work with the getBounds is to set the registration point of an object at runtime.
( )miniclip July 9th
This is an awesome tutorial. I have always want to stage fixed the flash content.
One question. I have created a animated web content containing:
Myweb.fla
Myweb.swf
Myweb.html
with some .js and xml files
How should i include these into the fluid layout.
( )Thank you
WhateverMan July 10th
Seriously…all that to get what? A tiny page with some text that does something super simple. Talk about lifting a car with your bare hands just to change the oil.
( )True September 27th
I agree, there was a lot of coding and time put into this just to end up with a useless empty imaginary webpage
( )daniel October 22nd
I think both of you are missing the point. The end result is merely to show what has been applied, and isn’t meant to be a final product. You’re learning techniques here, not how to create a website from scratch. If you have a simpler way to get this effect, by all means, share it.
Steve July 11th
Hi
I have added a MenuObject.as to your tutorial to add functionality to the menu. I would like to remove Middle on the click event but I am having difficulty in reference-ing the instance.
These give an error
_stage.removeChild(Middle);
_stage.removeChild(DisplayObject(Middle);
How can I reference and remove the Middle class instance.
Thanks for any help.
( )Kristian August 4th
+1
I have also tried to call the instances – but i can’t figure out what the middle “instance” is called..
Any help?
( )Thanks,
Kristian
VIlle August 29th
I have now tried for 17 hours to get my links work and every time I end up in somesort of an error message. I have tried to create eventHandlers in the Website.as -file as well to do them in .fla file but every time, no matter what I try and how many different tutorials I read, I allways end up with the #1069 error or something else.
I would be pleased to know even the basics of the MenuObject.as -file. Where do I import it? What do I have to write inside it? I dont have any in or out animations, I just would like to have my menu items (news_btn, about_btn and so on) change the frame of the middle-section where my stuff should be. Or if there is better way, like creating several middle-contents and then replacing the child or something it would be nice too. But just to get something chance to something instead of “one-single-line-of-code-more-and-black-screen”.
I’m sorry I don’t have any code-examples here coz my internet broke and I’m writing this with a another one.
( )roomi July 11th
how would you place a preloader?
( )Thales August 6th
how would you place a preloader?
( )Its not working with a preloader some one help?
ashish singh July 16th
it’s great tutorial
( )Emo July 19th
Could someone post a tutorial of how to continue with this? I mean, how do you put a section content? How do you load it? the main stage is always empty? This is a full tutorial….. buy i really need it FULL.
Thanks
( )Wonka July 20th
Hi, I am just wondering … I want to set parts of the app to motion. How can I access them in AS3, though they are not part of stage?
Sry for dumb question, but if anyone could help me …
( )meme July 23rd
how do we put content in the middle??
is it possible to put something in the middle without actionscript calling from the library??
goodwork!!
( )PSA July 25th
Step 1: DON’T MAKE A FLASH WEBSITE!!! Websites are supposed to be in HTML or XHTML. You can extend the website with Flash, PHP, and CSS, but the whole website should not be made in Flash! Even PHP produces HTML that the browser reads. Nobody likes Flash websites. They’re slow and annoying and don’t work on every platform. Don’t do it.
( )PiKE July 27th
@PSA Welome in 2009. There are minor probs in type declaration, nice work. I’ll gif it a try.
( )Justin Woods July 27th
@PSA … you don’t know what you’re talking about. Nobody says websites have to be made a certain way. These are all just tools to reach whatever creative output you want. I do primarily html/css and I think you are being narrow minded to the possibilities of flash. For instance, with higher bandwidths and processing abilities of our computers, the web is now having the ability to integrate more of a broadcasting medium. Who’s to say incorporating a broadcasting medium would be inappropriate… are we not seeing more interactivity and even the ability to watch televisions shows nowadays? It seems this is where the future of the web has been going. Nobody says you have to like it, but your opinion doesn’t speak for everybody else’s. Stop being pretentious, I’m getting so tired of people hopping onto this anti flash bandwagon. Go ahead and try to make UFC sites like Red Interactive does without flash… it wouldn’t make sense to.
( )Paul Sijpkes July 29th
I agree with Justin, Flash is the future. You only need CSS/HTML for text heavy sites but Flash is very well suited to displaying eye catchng graphics and interactivity well beyond what HTML and CSS can do at the moment. Flash is picking up from where Java left off in the nineties with Java applets, except SWFs are much easier to build and are approaching the kind of scalability that Java has using Flex and Actionscript 3.0.
Márcio Toledo August 3rd
Ridiculous comment… I see you in the future carrying a banner “I code XHTML and CSS for food”
( )Flash KicksAss August 19th
“Nobody likes Flash website” LoL
That was a great one lololololol
http://www.adidas.com
http://www.karllagerfeld.com
http://www.prada.com
http://www.gaultier.com
http://www.dior.com
http://home.disney.fr/
(many regional Disney sites..)
er…
wake up and smell the coffee.. flash in many ways is everywhere, so full sites or not…you cannto escape it: your vids are most likely FLV’s, Flash banners are all over the place… Flex is giving good face to databases etc etc.. it is almost 2010 by the way… I knew Flash would be big when I got my Macromedia Flash 3… Some people told me NO, some people also told me Apple would soon go bankrupt… I was told that every few years… dunno… people say weird meaningless unthought and unperceptive shit lol They lose, the seers win !
( )Alejandro July 29th
Excellent tutorial! What I like is that I can reuse the class without having to recode everything each time I have to make a new site. I previously used another technique in which I coded directly into the fla and had to define each object’s resizing separately. The only thing missing in my opinion is the option to stop resizing after a certain minimal window size is reached. I’m new to AS3, but I think that would involve an IF statement somewhere in the class. Maybe you could expand the tutorial to include this? Or maybe you could tell me where to modify the code so that it works that way?
Anyways, kudos and a big bow to you sir for a job well done!
( )nizar August 5th
Hey its so gud..
( )bernd August 8th
Very good tutorial !
( )Me and perhaps others would like to know how to reference the single items (middle, … ) in actionscript.
I am just building a website with this fluid layout.
With menu buttons I would like to change the content in the middle area,
setting child movies of “middle” to visible and unvisible.
makzan August 13th
Thank you very much.
For the middle part. I will make the reference of the main content (middle) movieclip a instance variable. And the main content part will be another classes that in charge of showing content. Then the menu can reference the content movieclip via instance variable and calling its own methods to switch to different materials.
For how to control the switching of different material in the content class. It will be another big topic of content management in flash. Simply setting the visible properties works fine.
( )Kristian August 11th
Yes.. I really can’t figure out how to reference the “middle” – and yes, I see others having the same problem as well..
( )Greg August 12th
This is a fantastic tutorial. How would we make the menu list active to be able to display new pages in the middle content area? Example: click on the contact us text to bring up an image or text over the middle area?
( )Devin August 15th
This is the easy part, check out my code below:
//buttons
eventListeners(); //Turns on button event listeners
handCursors(); //Turns on Hand Cursors at site launch
menu.home_btn.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
menu.home_btn.removeEventListener(MouseEvent.MOUSE_OUT, btnOut);
menu.home_btn.removeEventListener(MouseEvent.CLICK, btnHome);
menu.home_btn.useHandCursor = false; //Turns off Hand Cursor for Home Button (that’s the first page)
function eventListeners():void
{
menu.home_btn.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
menu.about_btn.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
menu.home_btn.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
menu.about_btn.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
menu.home_btn.addEventListener(MouseEvent.CLICK, btnHome);
menu.about_btn.addEventListener(MouseEvent.CLICK, btnAbout);
}
function handCursors():void
{
menu.home_btn.buttonMode=true; // Must turn movieclips on buttonMode
menu.about_btn.buttonMode=true;
menu.home_btn.useHandCursor = true; //turns on button mode for all buttons
menu.about_btn.useHandCursor = true;
}
function btnOver(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“over”);
}
function btnOut(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay(“out”);
}
//———–PAGE FUNCTIONS ———— \\
var exitTween:Tween;
var prevPage:MovieClip;
var currentPage:MovieClip = home;
/*
var newsX:XML;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest(“FluidLayout/news.xml”));
function onComplete(e:Event):void
{
newsX= new XML(loader.data);
trace(newsX);
}
*/
function btnHome(e:MouseEvent):void
{
menu.home_btn.gotoAndPlay(“out”); //plays button out animation
exitTween = new Tween(currentPage, “y”, Regular.easeInOut, currentPage.y, currentPage.y + 800, 30, false); //animate off old page
prevPage = currentPage;
currentPage = new Home();
addChild(currentPage); //adds the about page to the stage
exitTween.addEventListener(TweenEvent.MOTION_FINISH, animateOn);
currentPage.x = stage.stageWidth/2 -325; // add currentPage on stage in x position (centered off stage)
currentPage.y = stage.stageHeight;
eventListeners();
menu.home_btn.removeEventListener(MouseEvent.MOUSE_OUT, btnOut); //Disable Mouse Out functionality
menu.home_btn.removeEventListener(MouseEvent.CLICK, btnHome); //Disable Mouse Click functionality
menu.home_btn.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
handCursors();
menu.home_btn.useHandCursor = false;
}
function btnAbout(e:MouseEvent):void
{
menu.about_btn.gotoAndPlay(“out”); //plays button out animation
exitTween = new Tween(currentPage, “y”, Regular.easeInOut, currentPage.y, currentPage.y + 800, 30, false); //animate off old page
prevPage = currentPage;
currentPage = new About();
addChild(currentPage); //adds the about page to the stage
exitTween.addEventListener(TweenEvent.MOTION_FINISH, animateOn);
currentPage.x = stage.stageWidth/2 -325;
currentPage.y = stage.stageHeight;
eventListeners();
menu.about_btn.removeEventListener(MouseEvent.MOUSE_OUT, btnOut); //Disable Mouse Out functionality
menu.about_btn.removeEventListener(MouseEvent.CLICK, btnAbout); //Disable Mouse Out functionality
menu.about_btn.removeEventListener(MouseEvent.MOUSE_OVER, btnOver);
handCursors();
menu.about_btn.useHandCursor = false;
}
function animateOn(e:TweenEvent):void
( ){
new FluidObject(currentPage,middleParam);
removeChild(prevPage);
}
Filipe August 24th
I have just some questions:
-Where do you use this code, in the website.as or in the part action of an empty frame?
-In the “buttons” part, is it normal that there is nothing about the “about_btn”?
Thanks for all
PS: sorry for my english…
Devin Walker August 24th
OMG freaky, your code is like exactly the same as mine was.. it’s built out more but I just started building this website in Flash using the fluid layout 2 weeks ago and this is what I’ve gotten so far: http://www.dlocc.com/Fla/index.html <— If this link doesn't work email me… also, if you have questions let me know, I may be able to help you out.
Devin September 1st
Haha, I just realized my post above was referencing my own code! What a doof! Maybe I should have checked that the code was posted by ME! Hahah, oh well. Hope this helped someone!
Yudum October 22nd
Hi, thanks for this wonderful tutorial.
But i have a question. Where do i need to use the code u give for the active menu above? in website.as or the others? I tried but i couldnt do it. Please help me =)
thank you so much!
Devin August 14th
Great tutorial, I’m extending this website but want to preload it and this is causing me some problems. Has anyone put a preloader on this? If so, please help!
( )Filipe August 20th
Really nice tutorial!!! Thanks a lot…
Have a question, how can I make the background change is size following the ratio, like in this 2 websites bellow?
http://new.reebokclub.com.br/
http://www.hm.com/fr/#/startns/
Sorry for my bad english…
( )Filipe August 24th
Thats ok, I did it
… next step now…
( )Devin Walker August 24th
I posted before that I didn’t know how to preload this site, well I figured that out and have been building on the FluidLayout since about 2 weeks ago. Mind you, I’ve never coded anything in AS3 really, but have built several websites. The design on this one was bugging me, I still don’t really like it that much but I guess it’s ok to share. Hopefully this will give someone some ideas and maybe pass me some good suggestions.
The FluidLayout has caused several frustrations for me: first is animating on and off pages, backgrounds, and other movie clips so they stay in the right location. Second, as I stated before was preloading the site. Third was adding XML to the dynamic text boxes that animate on and off, and third was just styling. It wasn’t too hard though.
Now that I put it online I’m finding Safari runs the site horribly and Firefox is mediocre and sometimes the pages animate on and off funny or the background gets stuck on resizing. Oh well, at least IE runs it like butter.
Let me know what you guys think: http://www.dlocc.com/Fla/index.html
( )Pedro August 27th
Hi Kevin,
I think your http://www.dlocc.com/Fla/index.html is really really cool!
Could you please tell me where to place the script for the menu navigation?
Thanks
Pedro Copenhagen, Denmark
( )Devin September 1st
For the menu navigation I’d recomment placing your scripts inside the moviesclip rather than inside the website.as file. This way you can keep the code separate from the website actionscript file.
( )dsplz September 2nd
hi,
but i i have my eventListeners on the menu movieclip, i cant do any actions in the middle movieclip?
how did u do that?
regards
JK August 31st
Is it possible to set parameters from inside the timeline of the FluidObject instance?
I posted what I am trying to do in code here: http://www.pastie.org/pastes/599578
It throws no errors but the offsetX parameter is not changing.
Any suggestions??
( )VIlle August 31st
Once again,very nice scprit!
But please tell us how to reference those objects on the stage. After my own effort for several days I called my friend Flash guru to take over and after few hours we were nowhere still.
Thr promblem is, that those objects (middle, tittle, footer, menu..) does not have instance names. They are somehow randomly created, like trace(this.name) on the middle section brings up text “instance158″. Ok, then we changed those by naming them again in Website.as and the result is that we get the instance names to object what we want (exept stage, or root, wich is still randomly created to be “root1″).
Still no matter what, if I call middle part with eventHandler from menu, it says “Access of unindentified property..” and gives that errer code, wich I don’t remember.
Situation is the same if I make those eventHandlers in the stage, in the middle- or in the menu -object or in the website.as file, nothing can call anything from anywhere.
Devin there above has a perfectly good looking code, but he is referencing those objects like it would be simliest thing on earth.
So could someone please help? It would be appreciated.
( )VIlle August 31st
..and one more thing, why is that that when you put trace inside Website.as file, you get no output at all?
( )Devin September 1st
Ville,
Reference the object on stage through the Website.as file. The code I posted above I placed directly into the website.as file. So, for instance:
In the website.as file we see the Middle symbol is added to the stage through the code:
var middle = new Middle();
addChild(middle);
and aligned with:
var middleParam = {
x:0.5,
y:0.5,
offsetX: -home.width/2,
offsetY: -home.height/2
}
new FluidObject(middle,middleParam);
Now if we want to add code to whatever is in this middle position symbol (such as buttons, XML, whatever) you can easily add the symbol to the stage in the website.fla file and code within that movieclip all you’d like. You can also add the code to the website.as file but you have to first tell actionscript to go into that movieclip like so:
middle.myButton_btn.addEventListener(MouseEvent.Event, btnOver);
notice how “middle” precedes the button instance name? That’s because the button’s instance name is within that “middle” movieclip.
Do you understand what I’m getting at?
Once you get it you’ll be in the clear. Hope this helped!
VIlle September 1st
oh, in CS4 I do get output on trace inside website.as
( )Kristinn September 5th
Hi guys, First of all, thank you so much for the tutorial! It is mindblowing!
Second, I am new to flash, and I am going through tutorials to learn all this different stuff and trying to implement to a website I am making. One small question, I think, how can I:
Use this fluid layout, but have a background video, that fits to screen size.
I have both working but in two different files.
I achieve the “background video fit screen”:
Import video to stage, embed in timeline and use freeform to fill the stage with the video.
then:
Set html publish settings to 100% width and height.
And by doing this tutorial I got the fluid layout working, but in a different file.
What I am basically asking you guys for is: how can I implement both features into one webpage??
I have tried this, but the video does not resize in browser, Chrome.
Thanks alot!
p.s.
reference(not fluid though):
http://www.hellomonday.net these guys use the fullscreen feature in their works.
( )Kristinn September 5th
http://www.workingelement.com/
This is a better example.
Kristinn
( )Devin September 6th
This should be a relatively simple, but we all know how that can be sometimes. Shoot me an email and I’d be happy to look at your code!
pcasa September 9th
Great Tutorial.
Preloader help would be great.
Tried AS3 preloader from gotoandlearn but don’t know how to reference Website.as.
( )Mihails September 10th
Amazing tutorial!
( )However I’ve stucked. I’ll be pleased if somebody will be able to help me.
So I have same menu and, for example, 3 keyframes in the “middle”. How can I control these keyframes by click on the different button in the menu?
I tried to use Devin’s code, but it still did not work. Maybe I put it in the wrong place (where exactly did you paste this code, Devin?). I have same problems as VIlle had. Could somebody help me with that?
Paul September 21st
Hi,
so, everything is working so far, but I have one question. I have a FLV playing in the background and I wanted to know how I can get the video to scale to the browser’s size and keep the other elements “fluid” ?
Thanks!
( )Bebop October 4th
You are the best, very good and useful tutorial
( )Moses Adeniyi October 6th
Excellent tutorial
( )Alexandre October 17th
Can someone pass through all the questions and answer them?
( )Thanks
Chris October 19th
I have no doubts that this is a very outstanding and excellent tutorial.
( )But in my opinon this is a technique which can easily be done in CSS (provided the use of a moden browser. By modern I do not mean IE.)
Dave October 19th
Has anyone gotten this to work with Gaia
Currently I have this error:
Gaia Framework (AS3) v3.1.9
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.gaiaframework.FluidLayout::FluidObject()
at pages::MemberPage()
I believe the error is coming from the FluidObject.as file and has to do with referencing the stage.
When I comment out all the referneces to the stage it runs but the fluid layout does not work. I have heard I need to use the ADDED_TO_STAGE but I have no idea how that works.
Any suggestions?
( )Hussein October 26th
i duno whats Gaia is.
But concerning added to stage. you need to do the following.
public function Website()
{
this.addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e)
{
anything to do with stage scaling goes in here.
……
}
hope that helped, the Fluidlayout works fine on IE, but on Mozilla, u need to refresh the page or resize it.
( )Tonymo October 20th
It has a problem like refreshing the webpage.
( )John November 3rd
Hi, this is a great tutorial, thank you very much but how do put a button on the menu in as3, I am a beginner, the tutorial I did well, excuse my English and my silly question hehe, thanks
please help me!!
( )Fercho November 9th
Hi, i’m new in as3, i follow the tutorial and it’s amazing congratulations and thanks for the share. Im building a fluid website and i just have a question: How can i resize the mc’s?
If anyone can help me i will appreciate it so much.
Thanks
( )Fercho November 11th
Of course, resize the mc’s depending on the stage resize. I mean convert some mc’s into rezisable (not bg) and some mc’s not rezisables (middle or footer or menu…)
( )Matt November 11th
nice tut, but how does this work when working on more than just the index page?
Its nice to have the main page resize but what about linking to other pages and making that content resize too
How would i go about doing that?
( )Eric Salvi November 25th
Had a question about width and height, can you add those to something like this?
var menuParam = {
x:1,
y:0,
width: 0,
height: 1,
offsetX: -menu.width – 20,
offsetY: 20
}
new FluidObject(menu,menuParam);
So for instance the background we want scaled 100% both width and height?
( )John December 1st
how would you do the navigation button for this. Like making the buttons work?
( )Eduardo Felipe Amaral December 7th
I have a problem, when I load an external swf, when entering the site the times he does not resize it, and then it only when I resize the window restoration, what do I do? ( i’m from brazillian )
( )Devin Walker December 8th
What’s up everyone?
I’ve had different people asking about how I added buttons and preloaders (also included MP3 player, background effects and contact form) for this Fluid Website tutorial. I decided to offer up my code @
http://www.dlocc.com/articles/flash-fluid-website-template-tutorial-and-download/
You can find an explanation of the code and download my the .FLA in a zip with all the classes and everything. Here’s a demo of the website I created from this tut http://www.dlocc.com/downloads/fluid/index.html
Hope this helps!
( )Muzaffar December 19th
This is very nice tut. I would appreciate if you will also define, on how to set url for the title and how to load the target movie clip on the stage. Thanks
( )jorge December 20th
Great tutorial, been looking for this for a while
( )haku December 21st
your awsome
( )John Martin February 2nd
Hello.
What about google indexation? This fuid layout will be indexed by google or others?
Thanks.
( )