EasyCFM.COM ColdFusion Forums / Flex Development / CF_Flex 2-based, database-driven banner ad rotator

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: CF_Flex 2-based, database-driven banner ad rotator

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

stinasius
03-22-2008 @ 7:28 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

hi how can i create a database driven ad rotator in flex and coldfusion? i wanna add it on my website.

kicker
03-22-2008 @ 10:14 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

Ok, this is a really quick and dirty solution you will need to tailor it to your needs, but the basics are there.

Here is the cf code.

< cfcomponent>
     < cffunction name="adrotator" access="remote" returntype="string">
          < cfquery datasource="yourdb" name="getCount" cachedwithin="#CreateTimeSpan(0,0,1,0)#">
             Select ADID
            From AD_tble
        < / cfquery>
        < cfset randomAd = randRange(1,getCount.recordcount)>
        < cfquery datasource="yourdb" name="qAds">
             Select AD
            From AD_tble
            Where ADID = < cfqueryparam cfsqltype="cf_sql_integer" value="#randomAd#">
        < / cfquery>
        < cfset adtoshow = qAds.AD>
        < cfreturn adtoshow>
     < / cffunction >
< / cfcomponent >


The first query is cached so we don't need to call it every time to get a count. You can increase or decrease the cache time to your liking. Right now it is set to one minute.

here is the actionscript (again quick and dirty)

import flash.utils.Timer;
               import flash.events.TimerEvent;
               
               private var adTimer:Timer = new Timer(30000);
               
               private function initAds():void
               {
                    adTimer.addEventListener(TimerEvent.TIMER, getNextAd);
                    adTimer.start();
               }
               
               private function getNextAd(evt:TimerEvent):void
               {
                    //call remote object or webservice will fire every 30 seconds you and increase or decrease the frequency you would
                    //use the event listener for your remote object or webservice to handle the information returning and applying it.
               }



The initADs function can be called at creation complete or later your choice.

Anyway there it is, very basic and a great jumping point for rotating ads. Again I suggest altering it to your needs and requirements.

Craig

This message was edited by kicker on 3-22-08 @ 10:15 AM

stinasius
03-24-2008 @ 8:12 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

hi do i link the image source to the remote object?

kicker
03-24-2008 @ 11:14 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

Ok, in your database (the one that stores the ads you want to rotate) you would have a link (be it http://mysite.com/images/ads/ad01.jpg or images/ads/ad01.jpg)
When you query the webservice or remote object function that gets the queries for the ad to show, you will need to define an event handler for the results. Within this event handle you would apply the link to the add to either a mx:Image component or to a mx:SwfLoader component based on which ones you are accepting maybe both.

Then you would use the source attribute of those components to load youre link. Something like:


private function myResultHandler(evt:ResultEvent):void
{
     myAdImg.source = evt.result;
}


In the code within my first response to you "AD" was the link to the file's location. That was my fault for not clarifying that.

Hope that helps

Craig

stinasius
03-25-2008 @ 10:03 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Junior Member
Posts: 109
Joined: Jan 2007

your solution worked well but it presented another problem. i have an upload form on the flex website that i use to upload adverts to a folder on the server and then inserts only the image name into the database, how can i insert the image path into the database.
note: i had to go into the database manually to add the path to the images. but if this is hosted then it wont be possible.

kicker
03-25-2008 @ 11:49 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 717
Joined: Oct 2004

That seems like one that can easily be fixed use the cffile returned info to get the directory and filename and use that to insert the path for the db.

Craig


Website Designed and Developed by Pablo Varando.