Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

How to display an SWF at 100%

This is a discussion on How to display an SWF at 100% within the Tutorials forums, part of the English Forums category; Do you have present those Flash applications that are visualized to 100% on the user"s browser" To be able ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 22-10-07, 07:43
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
How to display an SWF at 100%

Do you have present those Flash applications that are visualized to 100% on the user"s browser"

To be able to work with those characteristics, we must modify the publish settings of the SWF, more precisely the HTML file created by Flash, so that our SWF expands or tightens in base of the user"s screen resolution...
Done this, we owe to work with Actionscript 3.0 to maintain the objects (MovieClip, text fields etc"etc") to the right position whatever is the size taken by our SWF.

Also, we can impost a listener to an event in case the screen resolution is changed and so to reposition the object as needed.

Let us see how to do it"

I create a FLA and save it as "main.fla".
I keep the default size: 550x440.
A level named "sfondo" into which I insert a MovieClip with an instance name "bg_mc" of rectangular shape, of the same size as the stage and with a registration point at the top left.

Next, I go under the publish settings and in the HTML tab, I impost the following settings:

setting

Flash has created an HTML file named "main.html".
I open it (I personally use Dreamweaver but any text editor would do) and I impost all the margins to zero from the property panel for the page, as shown in the following pic:

setting

Now, I create a Document Class, an AS file saved as "Main.as", implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	
	public class Main extends MovieClip
	{
		public function Main()
		{
			init();
		}
		
		private function init():void
		{
			stage.frameRate=31;
			
			bg_mc.x=0;
			bg_mc.y=0;
			bg_mc.width=stage.stageWidth;
			bg_mc.height=stage.stageHeight;
		}
	}
}
into the method init:
I impost the frame rate
stage.frameRate=31;
I tell "bg_mc" to position itself to the coordinates 0,0 and to take a width and height equal to the stage width and height. Doing so, whatever is the size of the browser windows, the SWF will be displayed at 100%
bg_mc.x=0;
bg_mc.y=0;
bg_mc.width=stage.stageWidth;
bg_mc.height=stage.stageHeight;

We obtain the following result:
TEST 1

Clearly if we had systematized some objects on stage, we will notice that if we test the SWF without the HTML files (in its original dimensions) the objects would be to the correct place, while if they had been in the example of the preceding link they would be moved.

I make an example, I add a rectangular MovieClip with a central registration point and with an instance name "clip_mc" to the centre of the stage and I get this result:






Let us look at it now at a resolution of 100%:
TEST 2

It is not centred anymore! "clip_mc" is not anymore at the centre of the stage.

At this point, we need to act, using Actionscript and in the method init(), we add:
clip_mc.x=stage.stageWidth/2;
clip_mc.y=stage.stageHeight/2;
We tell Flash that "clip_mc.x" must be placed exactly at half the stage width and that its y is placed at half the stage height.

Now, it is centred:
TEST 3

Another example. Let us use a text field (rights_txt) which must be placed at the bottom of the stage height, the following way:






If we publish it at 100% without Actionscript, we will have the following result:
TEST 4

Once again, it is not placed where it should be as the SWF is bigger.

Once again, we use Actionscript:
I import the textField Class
import flash.text.TextField;
and I impost the text field coordinates, its x needs to be to the maximum stage width less the width of the text field itself and its y to the maximum stage height less the height of the text field itself
rights_txt.x=stage.stageWidth-rights_txt.textWidth;
rights_txt.y=stage.stageHeight-rights_txt.textHeight;

doing so, even at a resolution of 100%, the text field will be positioned correctly:
TEST 5

Important!
What would happen if the user ridimensions the browser windows with our SWF displayed at 100%"
Simple. The objects would not position themselves following the flow of the page.

Do try yourself to ridimension the window:
TEST6

In this case, we add a listener to the event RESIZE which will tell us when our SWF is being ridimensioned.
I explain next how to use it:
I import the event
import flash.events.Event;
I add a call to a method immediately after the call of init()

checkResize();
I create the method checkResize
Code:
private function checkResize():void
{
I add a listener to the stage to the event RESIZE of the Event Class which will call the function resizeStage 
stage.addEventListener(Event.RESIZE, resizeStage);
}
The function resizeStage will call the method init() which will position the objects found on stage 
private function resizeStage(event:Event):void 
{
init();
}
Try now to ridimension the window:
TEST 7

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !

Last edited by Flep; 28-08-08 at 06:36..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 18-12-07, 16:46
Member
 
Join Date: Dec 2007
Posts: 42
Rep Power: 0
appi is on a distinguished road
Re: How to display an SWF at 100%

I get it , thanks! However, I cannot work on the Y position of my movieClip it stays at the top of the browser while I gave the following parameters:

naviMC.y=stage.height/2;

Shouldn't it appear on the middle?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 18-12-07, 16:57
Onsitus's Avatar
CSS.FlepStudio.org
 
Join Date: Jul 2007
Location: Nettuno Beach
Posts: 973
Rep Power: 2
Onsitus is on a distinguished road
Re: How to display an SWF at 100%

Hi,

the right code should be:

naviMC.y=stage.stageHeight/2;

I don't know if it is a typing error on your post or if you really wrote it the way you did.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 18-12-07, 17:20
Member
 
Join Date: Dec 2007
Posts: 42
Rep Power: 0
appi is on a distinguished road
Re: How to display an SWF at 100%

Thanks! It works.

I guess it was a bad typing!!!

I have a few questions now:

Following this example. Do I have to create any object of my site in the init() ?

But what I would like to do it is able to split my page in class with the different content of the site in order to don't mess with the code. Have you got any example here where I could have a look at it?

I would appreciate that.

Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 21-12-07, 21:15
this.AS_newb();
 
Join Date: Nov 2007
Location: San Francisco, CA
Posts: 29
Rep Power: 0
theuprock is on a distinguished road
Send a message via AIM to theuprock
Re: How to display an SWF at 100%

I'm wondering if this example applies to something such as this. I was trying to figure out how to get something to align to the side of the browser, much like the menu does in this example -- Merijn Straathof - Personal portfolio -- but couldn't figure it out exactly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Flash Multi Gallery
  #6 (permalink)  
Old 21-12-07, 22:36
Member
 
Join Date: Dec 2007
Posts: 42
Rep Power: 0
appi is on a distinguished road
Re: How to display an SWF at 100%

I have a new problem here!

Following this code example, I have an array with buttons which are added to a movieclip which is located in the stage in relation with its width and height.

Because of the loop when I resize the browser the function resizeStage(event:Event):void calls the method where the elements are on the stage. As a consequence, the array loops and the buttons appear repeated as much times I resize the browser.

Could anyone knows how can I stop the array to do that?

At the moment, the only solution I found is comment the method called at the resizeStage event. Obviously, i have to refresh the browser anytime the browser is resized.

Can anyone give me a hand on this?

Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #7 (permalink)  
Old 22-12-07, 00:15
this.AS_newb();
 
Join Date: Nov 2007
Location: San Francisco, CA
Posts: 29
Rep Power: 0
theuprock is on a distinguished road
Send a message via AIM to theuprock
Re: How to display an SWF at 100%

I see what you're saying, but I can't help. Logically, I can see why the swf would want to do it, but I'm not sure of a solution.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #8 (permalink)  
Old 17-04-08, 13:44
Junior Member
 
Join Date: Jan 2008
Posts: 3
Rep Power: 0
madeonearth is on a distinguished road
Re: How to display an SWF at 100%

Hello,

I have tryed this tutorial, but no matter what I do, it just wont work for me.
At first I thought I misspelled some of the code, so I made a copy paste, still my MC want stretch at a 100%. I followed step by step and I'm getting very frustrated since most of you had no problem with it as I go to the replys.

This is what I get
main
What is wrong?
These are my work files, the MC on the stage and the Main.as Class. Just the same as the tutorial
http://www.madeonearth.be/stageResizeTest.zip

Is someone willing to please have a look at it?
I really would like this to work.

Many thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #9 (permalink)  
Old 17-04-08, 15:43
Onsitus's Avatar
CSS.FlepStudio.org
 
Join Date: Jul 2007
Location: Nettuno Beach
Posts: 973
Rep Power: 2
Onsitus is on a distinguished road
Re: How to display an SWF at 100%

Hi,

nothing wrong with your fla except it is missing the name of the document class (Main) in the property panel.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #10 (permalink)  
Old 18-04-08, 12:53
Junior Member
 
Join Date: Jan 2008
Posts: 3
Rep Power: 0
madeonearth is on a distinguished road
Re: How to display an SWF at 100%

Thank you so much, I really appreciate your help.
With the Class name Main in my property panel it does work.
Something I will never ever forget :)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
image display flex nitish dhar FLEX builder 3 0 07-07-08 14:37
Display List e accesso alle proprietà dei Movieclip f_ferrau Actionscript 3.0 base 1 24-03-08 08:18
tween display above loaded swf jimbo Actionscript 3.0 newbies 10 16-10-07 15:29
Display Object Container e gestione classi tem Actionscript 3.0 avanzato 5 22-08-07 13:45


All times are GMT. The time now is 19:16.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406