Groups | Blog | Home
all groups > flash actionscript > december 2005 >

flash actionscript : Banner rotation - anyone?


David Stiller
12/28/2005 5:08:15 PM
Gompe,

[quoted text, click to view]

Okay.

[quoted text, click to view]

Here two problems I see. The JavaScript document.write() method writes
content to the HTML document. So far, so good. But what you're asking
JavaScript to do is to set your SWF as the src of an <img> element. SWF's
cannot be embedded this way. They must be embedded via <embed> and <object>
elements. Use Flash to publish your SWF to HTML, then view source to see
how the <embed> and <object> elements (along with <object>'s <param>
elements) need to be. You must re-create these lines with your
document.write() statements. It's not hard ... just tedious. Notice that
each string in every line of document.write() is wrapped in single quotes
with escaped double quotes. There are other ways to handle this, but the
provided technique is fine.

In addition, you're wrapping your SWFs inside anchor (<a>) elements.
SWF's aren't clickable in the way images are, so you can leave off the <a>
part, both here and in your url variable earlier on (alt is out, too, since
SWFs' <embed> and <object> elements don't have alt attributes). You'll have
to use getURL() inside each of your SWFs to re-create the hyperlinking as
provided by those <a> elements.

As a matter of fact, it's much easier to just do this banner rotation
inside Flash entirely. Create an empty "container" SWF and embed it in your
HTML page, then use MovieClip.loadMovie() in cahoots with Math.random() to
load your various SWFs right from within the container SWF. No need for
JavaScript at all.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."

Gompe
12/28/2005 9:39:38 PM
Hi, I have read through alot of different sites and forums, and I can't find a
script that solve my issue. I need a script that show banner on a rotation each
time a new page loads. Those banners will be at the top of the page.

I also know that I need a script that use the object string, here's a copy of
what I have done 2 times:

<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var how_many_ads = 2;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
url="http://www.dvdbasen.no";
alt="dvdbasen.no";
banner=http://www.dvdanmelderen.com/amiban...anner_test6.swf;
width="768";
height="150";
}
if (ad==2) {
url="http://www.dvdbasen.no";
alt="dvdbasen.no";
banner=http://www.dvdanmelderen.com/crash/...anner_test6.swf;
width="768";
height="150";
}
document.write('<center>');
document.write('<a href=\"' + url + '\" target=\"_top\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0><br>');
document.write('<small>' + txt + '</small></a>');
document.write('</center>');
// End -->
</SCRIPT>

The other one I started to work on is this:

<SCRIPT LANGUAGE="JavaScript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var how_many_ads = 2;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
url="http://www.dvdbasen.no";
alt="dvdbasen.no";
banner="http://www.dvdanmelderen.com/amiban...anner_test6.swf";
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pu...version=7,0,0,0" width="768"
height="150" id="amityvillebanner_test6" align="middle";
param name="allowScriptAccess" value="sameDomain";
param name="movie"
value="http://www.dvdanmelderen.com/amiban...anner_test6.swf";
param name="quality" value="high";
param name="bgcolor" value="#ffffff";
embed src="amityvillebanner_test6.swf" quality="high" bgcolor="#ffffff"
width="768" height="150" name="amityvillebanner_test6" align="middle"
allowScriptAccess="sameDomain" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer";
width="768";
height="150";
}
if (ad==2) {
url="http://www.dvdbasen.no";
alt="dvdbasen.no";
banner="http://www.dvdanmelderen.com/crash/...anner_test6.swf";
width="768";
height="150";
}
document.write('<center>');
document.write('<a href=\"' + url + '\" target=\"_top\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0><br>');
document.write('<small>' + txt + '</small></a>');
document.write('</center>');
// End -->
</SCRIPT>

So I wonder if I have to do something with the document.write patterns??

anyone?

Thank you in advance....

Gompe
12/29/2005 11:01:55 AM
I forgot to ad the the last script I did in the first post.

Here? the scripts.



<script language="javascript">

// SPECIFY THE NAME OF BANNER HERE

// REMEMBER THAT NAME OF VARIABLE AND ARGUMENT PASSED
SHOULD BE SAME

// HERE IT IS 'banner1'

banner1 = new Banner('banner1');



// ADD THE BANNER HERE

// FIRST ARGUMENT : "FLASH" OR "IMAGE"

// SECONG ARGUMENT: PATH OF THE FILE

// THIRD ARGUMENT : DURATION IN SECONDS

// FOURTH ARGUMENT : HEIGHT

// FIFTH ARGUMENT : WIDTH

// SISTH ARGUMENT: HYPERLINK

banner1.add("FLASH", "banners/3.swf", 200, 150,
768,"");

banner1.add("FLASH", "banners/4.swf", 320, 150,
768,"");



// START THE BANNER

document.write(banner1);

banner1.start();

</script>



This is the js file:



// BANNER OBJECT

function Banner(objName){

this.obj = objName;

this.aNodes = [];

this.currentBanner = 0;



};



// ADD NEW BANNER

Banner.prototype.add = function(bannerType, bannerPath, bannerDuration,
height, width, hyperlink) {

this.aNodes[this.aNodes.length] = new Node(this.obj +"_"+
this.aNodes.length, bannerType, bannerPath, bannerDuration, height, width,
hyperlink);

};



// Node object

function Node(name, bannerType, bannerPath, bannerDuration, height, width,
hyperlink) {

this.name = name;

this.bannerType = bannerType;

this.bannerPath = bannerPath;

this.bannerDuration = bannerDuration;

this.height = height

this.width = width;

this.hyperlink= hyperlink;

// alert (name +"|" + bannerType +"|" + bannerPath +"|" +
bannerDuration +"|" + height +"|" + width + "|" + hyperlink);

};



// Outputs the banner to the page

Banner.prototype.toString = function() {

var str = ""

for (var iCtr=0; iCtr < this.aNodes.length; iCtr++){

str = str + '<span name="'+this.aNodes[iCtr].name+'" '

str = str + 'id="'+this.aNodes[iCtr].name+'" ';

str = str + 'class="m_banner_hide" ';

str = str + 'bgcolor="#FFFCDA" '; // CHANGE
BANNER COLOR HERE

str = str + 'align="center" ';

str = str + 'valign="top" >\n';

if (this.aNodes[iCtr].hyperlink != ""){

str = str + '<a
href="'+this.aNodes[iCtr].hyperlink+'">';

}



if ( this.aNodes[iCtr].bannerType == "FLASH" ){

str = str + '<OBJECT '

str = str +
'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '

str = str +
'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#v
ersion=6,0,0,0" '

str = str +
'WIDTH="'+this.aNodes[iCtr].width+'" '

str = str +
'HEIGHT="'+this.aNodes[iCtr].height+'" '

str = str +
'id="bnr_'+this.aNodes[iCtr].name+'" '

str = str + 'ALIGN="" '

str = str + 'VIEWASTEXT>'

str = str + '<PARAM NAME=movie VALUE="'+
this.aNodes[iCtr].bannerPath + '">'

str = str + '<PARAM NAME=quality
VALUE=high>'

str = str + '<PARAM NAME=bgcolor
VALUE=#FFFCDA>'

str = str + '<EMBED ';

str = str +
'src="'+this.aNodes[iCtr].bannerPath+'" '

str = str + 'quality=high '

// str = str + 'bgcolor=#FFFCDA '

str = str +
'WIDTH="'+this.aNodes[iCtr].width+'" '

str = str +
'HEIGHT="'+this.aNodes[iCtr].height+'" '

str = str +
'NAME="bnr_'+this.aNodes[iCtr].name+'" '

str = str + 'ALIGN="center" '

str = str +
'TYPE="application/x-shockwave-flash" '

str = str +
'PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">'

str = str + '</EMBED>'

str = str + '</OBJECT>'

}else if ( this.aNodes[iCtr].bannerType == "IMAGE" ){

str = str + '<img
src="'+this.aNodes[iCtr].bannerPath+'" ';

str = str + 'border="0" ';

str = str +
'height="'+this.aNodes[iCtr].height+'" ';

str = str +
'width="'+this.aNodes[iCtr].width+'">';

}



if (this.aNodes[iCtr].hyperlink != ""){

str = str + '</a>';

}



str += '</span>';

}

return str;

};



// START THE BANNER ROTATION

Banner.prototype.start = function(){

this.changeBanner();

var thisBannerObj = this.obj;

// CURRENT BANNER IS ALREADY INCREMENTED IN cahngeBanner() FUNCTION

setTimeout(thisBannerObj+".start()",
this.aNodes[this.currentBanner].bannerDuration * 1000);

}



// CHANGE BANNER

Banner.prototype.changeBanner = function(){

var thisBanner;

var prevBanner = -1;

if (this.currentBanner < this.aNodes.length ){

thisBanner = this.currentBanner;

if (this.aNodes.length > 1){

if ( thisBanner > 0 ){

prevBanner = thisBanner - 1;

}else{

prevBanner =
this.aNodes.length-1;

AddThis Social Bookmark Button