After much distress trying to figure out how to do this, I have finally got most of it working. My goal was to use the data in my banners db to pull a random entry and display that banner inside of my flash header. I have created a php page that passes 3 variables to flash:
link=link location
image=image location
alt=alt text (dont know how to use it in flash)
these entries are used on my site to be displayed on various pages. i wanted the same for my header banner without editing the .fla file. So this is what I got. The entries are getting randomly pulled from the db in the php, passes to flash in this format:
link=http%3A%2F%2Fclick.linksynergy.com%2Ffs-bin%2Fclick%3Fid%3D6f3RrfxE4Qs%26offerid%3D47092.1 0000116%26type%3D4%26subid%3D0ℑ=http%3A%2F%2Fbanne r.motorcycle-usa.com%2Fads%2F468x60_CS2.gif&alt=Shift Jacket
I used urlencode() to encode the URLs because they contain their own queries. This is the code I am using in the PHP file:
Code:
<?
$MYSQL_SERVER = 'db432.perfora.net';
$MYSQL_USER = 'dbo186625772';
$MYSQL_PASS = '********';
$MYSQL_DBNAME = 'db186625772';
$dbconnection = @mysql_connect($MYSQL_SERVER, $MYSQL_USER, $MYSQL_PASS) or die("Unable to connect to the mysql server<br>". mysql_error());
$db = @mysql_select_db($MYSQL_DBNAME, $dbconnection) or die("Couldn't select database.<br>" . mysql_error());
$sql = "SELECT * FROM phpbb2_banners ORDER BY RAND();";
$result = @mysql_query($sql,$dbconnection) or die("Could not obtain banner info.<!--" . mysql_error() . "<br>$sql-->");
if ($result) {
$row = mysql_fetch_array($result);
$imglink = $row["banner_link"];
$imgwww = $row["banner_www"];
$imagedesc = $row["banner_description"];
}
//$bannercode = "<a target='_blank' title='".$imagedesc."' href='".urlencode($imgwww)."'><img border=0 src='".urlencode($imglink)."'></a>";
//$banner = "banner=" . $bannercode . "";
$banner = "link=".urlencode($imgwww)."&image=".urlencode($imglink)."&alt=".$imagedesc;
echo $banner;
?>
This is the actionscript in the first frame of the flash file:
Code:
myVars = new LoadVars();
myVars.onLoad = function()
{
bannerImage.loadMovie(this.image);
}
myVars.load("http://s170193323.onlinehome.us/MKPortalSMF/bannerphp.php");
and this is the actionscript for the blank movieclip that loads the dynamic image:
Code:
on (press)
{
if (_root.myVars.link != undefined) {
getURL(_root.myVars.link);
}
}
I know the variables are getting passed to flash correctly because when i debug i can list the vars and they are correct, as follows:
Code:
Level #0:
Variable _level0.$version = "WIN 8,0,22,0"
Variable _level0.myVars = [object #1, class 'LoadVars'] {
onLoad:[function 'onLoad'],
link:"http://click.linksynergy.com/fs-bin/click?id=6f3RrfxE4Qs&offerid=47092.10000027&type=4&subid=0",
image:"http://banner.motorcycle-usa.com/ads/Alps468x60.gif",
alt:"AlpineStar"
}
Movie Clip: Target="_level0.instance1"
Button: Target="_level0.instance1.instance2"
Variable _level0.instance1.instance2.scale9Grid = [getter/setter] undefined
Variable _level0.instance1.instance2.filters = [getter/setter] [object #3, class 'Array'] []
Variable _level0.instance1.instance2.cacheAsBitmap = [getter/setter] false
Variable _level0.instance1.instance2.blendMode = [getter/setter] "normal"
Variable _level0.instance1.instance2.tabIndex = [getter/setter] undefined
Movie Clip: Target="_level0.bannerImage"
and for my problem, the link does not work. I can load the movie and it will randomly pull the vars and assign them correctly, posts the banner image, but does not do anything when you click the link. The link does not process because for some reason it wont pass the IF statement. if i remove the IF it will process getURL but will only look for file 'undefined'.
here is a link to the SWF in action, and to the SWF itself. it is not protected from import, so feel free to dl and import it if you know whats up. ill go ahead and attach the FLA just in case. thanks guys!
http://s170193323.onlinehome.us/MKPortalSMF/index.php
http://s170193323.onlinehome.us/MKPo...inal_bl_sm.swf
http://s170193323.onlinehome.us/MKPo...inal_bl_sm.fla