Current location: Hot Scripts Forums » General Web Coding » JavaScript » mBanner


mBanner

Reply
  #1 (permalink)  
Old 01-09-07, 12:02 AM
raven80 raven80 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
mBanner

Hi, I'm newbie here and in javascript, I have a problem please help me.
I used mBanner.js for my banner system until MS fix IE: display "Click to activate and use this control" on Flash banner.

I found this javascript to display Flash banner alone is ok.
Code:
function flashWrite(url,w,h,id,bg,vars){
    var flashStr=
    "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+w+"' height='"+h+"' id='"+id+"' align='middle'>"+
    "<param name='allowScriptAccess' value='always' />"+
    "<param name='movie' value='"+url+"' />"+
    "<param name='FlashVars' value='"+vars+"' />"+
    "<param name='wmode' value='transparent' />"+
    "<param name='menu' value='false' />"+
    "<param name='quality' value='high' />"+
    "<embed src='"+url+"' FlashVars='"+vars+"' wmode='transparent' menu='false' quality='high' width='"+w+"' height='"+h+"' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
    "</object>";
    
    document.write(flashStr);
}
When I modifies mBanner.js code which display Flash banner like above function, it not work.

Code:
// BANNER OBJECT
function Banner(objName)
   {
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner =Math.floor(Math.random()*3);
	};

// 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 = ""
	
	//alert(this.aNodes.length);
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++) //old: iCtr=0
	    { 
	    //alert(pos);
		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+'" target="_blank">';
		}
		
		if ( this.aNodes[iCtr].bannerType == "FLASH" ){
			
			str=str+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
			str=str+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,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+'" align="middle" VIEWASTEXT> '
			str=str+ '<param name="allowScriptAccess" value="always" />'
			str=str+ '<param name="movie" value="'+this.aNodes[iCtr].bannerPath+'" />'
			str=str+ 'param name="FlashVars" value="'+vars+'" />'
			str=str+ '<param name="wmode" value="transparent" />'
			str=str+ '<param name="menu" value="false" />'
			str=str+ '<param name="quality" value="high" />'
			str=str+ '<embed src="'+this.aNodes[iCtr].bannerPath+'" wmode="transparent" menu="false" quality="high" width="'+this.aNodes[iCtr].width+'" height="'+this.aNodes[iCtr].height+'" name="bnr_'+this.aNodes[iCtr].name+'" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			str=str+ '</embed></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 changeBanner() 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-1)
	{
		this.currentBanner=0;
	}
	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;
			}
		}
		if (this.currentBanner < this.aNodes.length - 1){
			this.currentBanner = this.currentBanner + 1;
		}else{
			this.currentBanner = 0;
		}
	}
	

	if (prevBanner >= 0){
		document.getElementById(this.aNodes[prevBanner].name).className = "m_banner_hide";
	}
	document.getElementById(this.aNodes[thisBanner].name).className = "m_banner_show";
}
How can I fix it ? Help me.
Thank a lot
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-19-07, 05:15 PM
arturex arturex is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I am facing the some problem with the original mbanner script plus the link over a flash banner is not working also.
Any help on this community ???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-19-07, 06:58 PM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
I can't really help, but there exists an add-on for FireFox called "FlashBlock". It replaces any flash thingy with a button you can click to show the flash animation. Perhaps you can look up that add-on, and see how it works. It normally uses Javascript, so it should be helpful.
__________________
Jack Bauer makes Chuck Norris cry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-20-07, 03:25 AM
raven80 raven80 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
I solved my problem, just write the string out instead of returning

to arturex: put the link inside the flash using Action Script ( using getURL )

Code:
// Outputs the banner to the page
Banner.prototype.toString = function() {
	var str = ""
	
	//alert(this.aNodes.length);
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++) //old: iCtr=0
	    { 
	    //alert(pos);
		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+'" target="_blank">';
		}
		
		if ( this.aNodes[iCtr].bannerType == "FLASH" ){
			
			str=str+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
			str=str+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,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+'" align="middle" VIEWASTEXT> '
			str=str+ '<param name="allowScriptAccess" value="always" />'
			str=str+ '<param name="movie" value="'+this.aNodes[iCtr].bannerPath+'" />'
			str=str+ 'param name="FlashVars" value="'+vars+'" />'
			str=str+ '<param name="wmode" value="transparent" />'
			str=str+ '<param name="menu" value="false" />'
			str=str+ '<param name="quality" value="high" />'
			str=str+ '<embed src="'+this.aNodes[iCtr].bannerPath+'" wmode="transparent" menu="false" quality="high" width="'+this.aNodes[iCtr].width+'" height="'+this.aNodes[iCtr].height+'" name="bnr_'+this.aNodes[iCtr].name+'" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			str=str+ '</embed></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>';
	}
       document.write(str);
       str="";
       return str;
};
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 01-20-07, 03:11 PM
arturex arturex is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Hi Raven80,
thanks for the getURL tip.
pls post the complete script with the modification. I am not getting sucess ...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 01-22-07, 02:26 AM
raven80 raven80 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Here's the complete file mBanner.js with modification.

Code:
///////////////////////////////////
// File Name: mBanner.js       //
// By: Manish Kumar Namdeo //
//////////////////////////////////


// BANNER OBJECT
function Banner(objName)
   {
	this.obj = objName;
	this.aNodes = [];
	this.currentBanner =Math.floor(Math.random()*3);
	};

// 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 = ""
	
	//alert(this.aNodes.length);
	for (var iCtr=0; iCtr < this.aNodes.length; iCtr++) //old: iCtr=0
	    { 
	    //alert(pos);
		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+'" target="_blank">';
		}
		
		if ( this.aNodes[iCtr].bannerType == "FLASH" ){
			
			str=str+ '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" '
			str=str+ 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,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+'" align="middle" VIEWASTEXT> '
			str=str+ '<param name="allowScriptAccess" value="always" />'
			str=str+ '<param name="movie" value="'+this.aNodes[iCtr].bannerPath+'" />'
			str=str+ 'param name="FlashVars" value="'+vars+'" />'
			str=str+ '<param name="wmode" value="transparent" />'
			str=str+ '<param name="menu" value="false" />'
			str=str+ '<param name="quality" value="high" />'
			str=str+ '<embed src="'+this.aNodes[iCtr].bannerPath+'" wmode="transparent" menu="false" quality="high" width="'+this.aNodes[iCtr].width+'" height="'+this.aNodes[iCtr].height+'" name="bnr_'+this.aNodes[iCtr].name+'" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
			str=str+ '</embed></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>';
	}
       document.write(str);
       str="";
       return str;
};

// START THE BANNER ROTATION
Banner.prototype.start = function(){
	this.changeBanner();
	var thisBannerObj = this.obj;
	// CURRENT BANNER IS ALREADY INCREMENTED IN changeBanner() 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-1)
	{
		this.currentBanner=0;
	}
	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;
			}
		}
		if (this.currentBanner < this.aNodes.length - 1){
			this.currentBanner = this.currentBanner + 1;
		}else{
			this.currentBanner = 0;
		}
	}
	

	if (prevBanner >= 0){
		document.getElementById(this.aNodes[prevBanner].name).className = "m_banner_hide";
	}
	document.getElementById(this.aNodes[thisBanner].name).className = "m_banner_show";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 01-22-07, 12:01 PM
arturex arturex is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I am getting a undefined msg on html page with errors on line 60 'vars' in undefined and line 121 'document.getElementByld(...)' is null or not an object.
What I am doing wrong ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 01-22-07, 12:36 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
That means the script isn't finding one of the objects it's looking for. I can't be sure of the exact reason unless you post either your code or a link to the page.

I've modified the mBanner script before and added/changed stuff for people. You should be able to find it in this forum.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 01-23-07, 02:40 AM
raven80 raven80 is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by arturex
I am getting a undefined msg on html page with errors on line 60 'vars' in undefined and line 121 'document.getElementByld(...)' is null or not an object.
What I am doing wrong ?
just comment or erase this line:
str=str+ 'param name="FlashVars" value="'+vars+'" />'

Last edited by raven80; 01-23-07 at 02:45 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 01-23-07, 04:19 AM
arturex arturex is offline
Newbie Coder
 
Join Date: Jan 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
mbanner working

Thanks man ! is working now.´

By the way did you notice the only three first banners declared on html page are showed randomly as the initial ones after each refresh or page reload ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
mBanner Blues JavaScript 13 06-02-09 09:59 AM


All times are GMT -5. The time now is 12:03 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.