Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

flash page flip

Actionscript 3.0 video tutorials

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast
Results 1 to 10 of 30

Thread: How to display an SWF at 100%

  1. #1
    Administrator Living At The FlepStudio! Flep is on a distinguished road
    Join Date
    Jul 2007
    Posts
    5,609
    Rep Power
    9

    How to display an SWF at 100%

    flash templates
    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 !

  2. #2
    Member Settled In appi is on a distinguished road
    Join Date
    Dec 2007
    Posts
    42
    Rep Power
    0

    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?

  3. #3
    CSS.FlepStudio.org Moving My Stuff To The FlepStudio Onsitus is on a distinguished road Onsitus's Avatar
    Join Date
    Jul 2007
    Posts
    1,405
    Rep Power
    5

    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.

  4. #4
    Member Settled In appi is on a distinguished road
    Join Date
    Dec 2007
    Posts
    42
    Rep Power
    0

    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.

  5. #5
    this.AS_newb(); Settled In theuprock is on a distinguished road
    Join Date
    Nov 2007
    Posts
    29
    Rep Power
    0

    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.

  6. #6
    Member Settled In appi is on a distinguished road
    Join Date
    Dec 2007
    Posts
    42
    Rep Power
    0

    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.

  7. #7
    this.AS_newb(); Settled In theuprock is on a distinguished road
    Join Date
    Nov 2007
    Posts
    29
    Rep Power
    0

    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.

  8. #8
    Junior Member Settled In madeonearth is on a distinguished road
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    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!

  9. #9
    CSS.FlepStudio.org Moving My Stuff To The FlepStudio Onsitus is on a distinguished road Onsitus's Avatar
    Join Date
    Jul 2007
    Posts
    1,405
    Rep Power
    5

    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.

  10. #10
    Junior Member Settled In madeonearth is on a distinguished road
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    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 :)

+ Reply to Thread
Page 1 of 3 1 2 3 LastLast

Similar Threads

  1. import flash.display.Array???
    By nocciola in forum Actionscript 3.0 avanzato
    Replies: 2
    Last Post: 12-04-09, 05:41
  2. Problem to display image on DEV SERVER
    By boyzs in forum HELP free utilities
    Replies: 1
    Last Post: 15-03-09, 07:56
  3. image display flex
    By nitish dhar in forum FLEX builder 3
    Replies: 0
    Last Post: 07-07-08, 13:37
  4. tween display above loaded swf
    By jimbo in forum Actionscript 3.0 newbies
    Replies: 10
    Last Post: 16-10-07, 14:29
  5. Display Object Container e gestione classi
    By tem in forum Actionscript 3.0 avanzato
    Replies: 5
    Last Post: 22-08-07, 12:45

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts