www.webdeveloper.com
Results 1 to 3 of 3

Thread: Swfobject positioning

  1. #1
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161

    Swfobject positioning

    Hi everyone,
    this is probably an easy problem. I'm using swfobject to play a swf flash file on a landing page. I know the flash player will open it's own window to present the content. I thought if I specified 'wmode', 'opaque' the file would be "forced" into the flow of the web page and I could gain control of it's positioning. I used this wmode setting and yet the file keeps "doing it's own thing" and not appearing inside the div where I want to position it.

    The following is a stripped down version of my problem; the swf and swf object files are in the same directory; the swf file plays just fine, it just doesn't want to go into my div id="target_img":

    <head>
    <title>Home Page</title>
    <style type="text/css" >

    #target_img {
    position:relative;
    width: 300px;
    height:240px;
    top: 100px;
    left:300px;
    border:thin solid #33CC33;

    }
    </style>

    </head>
    <body>
    <div id="header">
    <img src="images/newhead2.jpg" alt="company icon" />
    </div><!--end header-->

    <div id="target_img"><img src="images/land.swf" /></div>
    <br /><br />
    <script type="text/javascript" src="images/swfobject.js"></script>
    <script type="text/javascript">
    var so = new SWFObject('images/land.swf','target_img','300','240','9');
    so.addParam('allowfullscreen','true');
    so.addParam('allowscriptaccess','always');
    so.addParam('bgcolor','#FFFFFF');
    so.addParam('flashvars','file=playlist.xml&autostart=true');
    so.addParam('wmode', 'opaque');
    so.write('target_img');
    </script>


    </body>
    </html>

    I've also tried moving the closing </div> to the position right after </script> but this has had no effect.

    I welcome any suggestions.

    captsig
    Last edited by captsig; 01-11-2011 at 12:11 PM.

  2. #2
    Join Date
    Feb 2008
    Location
    NW Washington State
    Posts
    1,856
    You may just be having positioning problems that have nothing to do with swfobject.
    For testing purposes, turn off swfobject by changing the file name in the <head> to
    Code:
    <script type="text/javascript" src="swfobject_off.js"></script>
    of course edit as per your exact src path. This will allow you to see the content of the div without Flash being involved. This is a good practice with swfobject anyway... get your alt content working first and only after that, do you turn on the Flash.
    Give #target_img the exact same dimensions as the .swf and give it a background color so you can see where it's being positioned. Now get all the positioning so that it works. You may be thrown off by the positioning "Parent Rule".
    From an old post:
    the actual display of #flash will very depending on whether or not it's parent container (<div>) also has a declared position.

    That is, if it's parent container DOES NOT also have a declared position, the child <div> will do 1 of 2 things.
    If position:relative, it will position as desired but space will be left as though that element was still in the natural flow. So you may move the 500 X 100 element down and over, but a 500 X 100 space will be left, as though it was still there.
    If position:absolute, child is positioned relative to browser window and that position does not change even if window contracts or expands.

    So be sure to give a declared position to both the parent and the child <div>.
    Once you get the positioning correct then change the file name of swfobject up in the head. If you are using swfobject 1.5 (which it looks like you are) all the script as well as the alt content will go INSIDE #target_img.
    Piece of cake!
    Here's a sample page using swfobject, alt content as well as a declared position to place one .swf on top of another:
    http://www.worldbarefootcenter.com/index.html
    The video player is placed on top of a different .swf.
    View the source code for more details.
    Best wishes,
    Eye for Video
    www.cidigitalmedia.com

  3. #3
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161
    'Eye-for-video' thanks for your response; you are always generous with your time for these postings.
    I found the problem; while trying to implement your comments I kept puzzling over the reference to the div id 'target_img' in the object statement:

    var so = new SWFObject('images/land.swf','target_img','300','240','9');

    this whole stretch of code is sitting in a div with id='target_img'; this could be the duplication I was seeing. Sure enough when I changed the object param of 'target_img' to something like 'my_img' (a div that didn't even exist) bingo, no duplication and the flash element played in the position I needed it.

    thanks again,
    captsig

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles