Okay. lol. I was about to tear my hair out a few minutes ago.
Basically, I have my flash movie spanning 100% width and 100% height. As soon as the flash movie loads, a logo is supposed to centered. How did I center it?
_root.mc_logo._x = (Stage.width / 2) - (_root.mc_logo._width / 2);
Ok, so technically, my logo is supposed to center itself based on the stage width. And it worked just fine in Netscape, Firefox and Mozilla.
Internet Explorer, on the other hand started giving me crap. In order to garauntee my .SWF file would not be cached by Internet Explorer, added a random variable to it so that the browser always thinks its a new .SWF file.
These are the lines the random key was used in the embed markup:
(note that the random key is a PHP variable, which was declared earlier in the page to generate the random key)
<param name="movie" value="swf/splash.swf?r=<?=$rKey?>">
<embed src="swf/splash.swf?r=<?=$rKey?>"
I figured this would be it. My .SWF would never be cached and I wouldn’t have to worry about opening a brand new window every time I exported my .SWF file for testing.
Alas, I accidentally stumbled upon a bug of some sort. Apparently, whenever I refreshed, everything worked fine… but, if I pressed the “GO” button on IE or pressed enter in the address bar, THE STAGE ENDED UP HAVING A WIDTH OF 0 AND A HEIGHT OF 0. This screwed things up because the logo wouldn’t align to the center based on the Stage.width and Stage.height in Flash.
I tried every caching method there was to stop this, but it didn’t work. As I delved into it further, I tried this Javascript code to take a look at the key that I had:
<script>alert('<?=$rKey?>');</script>
It turns out, every time that the stage was reduced to 0, the key was always the same too! That means that the page wasn’t refreshing when I pressed the “GO” button and or press ENTER in the address bar. Not only wasn’t it refreshing the page, but the PHP code wasn’t being executed either. The page was just “re-displaying”, or so to speak..
So, to solve this, I just added this tidbit of PHP code.
<?
$rKey = rand(rand(), rand())/rand(rand(), rand());
if (isset($_SESSION['oldKey'])) {
if ($rKey == $_SESSION['oldKey']) echo "<script>window.location = window.location</script>";// Refresh
}
$_SESSION['oldKey'] = $rKey;
?>
If the old key matches the new key, refresh the page.
I wonder if anyone has any better ideas…