A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Java Script for Flash Banner Rotation

  1. #1
    Junior Member
    Join Date
    Oct 2001
    Posts
    17

    Java Script for Flash Banner Rotation

    I am new to this Java Scripting stuff so I am looking for a little help. I have seen posted in here JavaScript for randomly displaying .fla files.
    What I am trying to accomplish is displaying flash banners in order (1.swf, 2.swf, 3.swf) along with a different url for each one. 1.swf always get the same url, 2.swf samething, etc.

    I have tried the Flash file approach tageting the external flash banners but I am running into problems with the main flash file taking the flash banners and making there background color transparent. I have no clue on that, so I gave up and am not exploring the Javascript idea. I got everthing to work with this code but I dont know how to change it to do what I stated above.

    Any help you guys could give me on this would be greatly appreciated.

    Here is the code I need to change some how:

    You'll are the greatest!!!

    var movies = new Array("b1.swf", "b2.swf", "b3.swf")
    var s_width = new Array("468","468","468")
    var s_height = new Array("60","60","60")

    len = movies.length;
    today=new Date();
    today=today.getTime()/10;
    temp_number=today%len;
    rnd = Math.round(temp_number);
    // Output into the source:
    document.writeln('<EMBED src="'+ movies[rnd] +'" quality=high WIDTH="'+ s_width[rnd] +'" HEIGHT="'+ s_height[rnd] +'" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
    document.writeln('</EMBED>');

    </script>

  2. #2
    Senior Member
    Join Date
    Jul 2001
    Posts
    2,467
    Here's a script I wrote a couple of years ago:



    <script>
    <!--
    /*
    ************************************************** *******
    *** "God so loved the world that he gave his only ***
    *** begotten son, so that whosoever believed in him ***
    *** would not perish, but have everlasting life." ***
    ************************************************** *******
    */

    function ranMov() {
    var myFlash = new Array()
    myFlash[0] = "banner1.swf";
    myFlash[1] = "banner2.swf";
    myFlash[2] = "banner3.swf";
    var ranNum = Math.floor(Math.random() * 3);
    document.write("<center><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://active.macromedia.com/flash4/cabs/swflash.cab#version=4,0,0,0' id='myFlash' width='475' height='400'><param name='movie' value='"+myFlash[ranNum]+"'><param name='quality' value='high'><param name='bgcolor' value='#ffffff'><embed name='myFlash' src='"+myFlash[ranNum]+"' quality='high' bgcolor='#ffffff' width='475' height='400' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed></object></center>");
    }
    //-->
    </script>
    <body onload="javascript:ranMov();">

    Just change the banner names--add as many as you like. Increment the random multiplican by 1 for each new movie. Make sure that the document.write(); statement is all on the same line.



    -james
    Last edited by jamescover; 06-24-2004 at 11:42 PM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life."

    Image Popup Scripting Engine | Thumb PopUp Script | HTML Anchors w/Flash | Popup Script Generator | Seq. Img Swap | Img Swap | Browser Shake | Rand. Img Swap | Inline Img Swap | Screen Res. PopUp | Screen Resolution Popup Script


  3. #3
    Junior Member
    Join Date
    Oct 2001
    Posts
    17
    I have placed your code into the html doc and nothing happens when the page loads.
    I renamed all of my b#.swf files to reflex the file names you had in your script and still nothing.

    Any Ideas or thoughts on this?

  4. #4
    Senior Member
    Join Date
    Jul 2001
    Posts
    2,467
    Hi:


    If you just copied and pasted it, it is because this board splits the word javascript. After you've copied and pasted the script, go to the following line...


    <body onload="javascript:ranMov();">

    ...and remove the space between java and script.


    Also, I'm using IE 5.0 and the script doesn't work when I use the refresh button, instead of the go button to refresh the page.




    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life."

    Image Popup Scripting Engine | Thumb PopUp Script | HTML Anchors w/Flash | Popup Script Generator | Seq. Img Swap | Img Swap | Browser Shake | Rand. Img Swap | Inline Img Swap | Screen Res. PopUp | Screen Resolution Popup Script


  5. #5
    Junior Member
    Join Date
    Oct 2001
    Posts
    17
    I have removed that space in the code. Now what happens is the page loads up and then...the page disappears and I get a 468 X 60 form box with the scroll bar on the RT hand side located at the top of the page, everything else is blank.

  6. #6
    Senior Member
    Join Date
    Jul 2001
    Posts
    2,467
    " I have removed that space in the code. Now what happens is the page loads up and then...the page disappears and I get a 468 X 60 form box with the scroll bar on the RT hand side located at the top of the page, everything else is blank. "

    Sorry, I don't know what you mean by a form box . But the script is set up to serve 475x400 movies. You can just change the dimensions to suit the size of your banners.

    Maybe, you're not familiar with what this script does--document.write(), writes to a new page. That is, it produces a new HTML page at runtime/on-the-fly, just like the script you posted originally. If that's not what you want it to do, you'll have to better explain what you're try to accomplish.



    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life."

    Image Popup Scripting Engine | Thumb PopUp Script | HTML Anchors w/Flash | Popup Script Generator | Seq. Img Swap | Img Swap | Browser Shake | Rand. Img Swap | Inline Img Swap | Screen Res. PopUp | Screen Resolution Popup Script


Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center