Reputation: 12042
I want in my Flex app to redirect to an HTML page if the user doesn't have Flash installed. I noticed in the HTML generated by Flash it has:
<div id="flashContent">
<p>
To view this page ensure that Adobe Flash Player version
10.0.0 or greater is installed.
</p>
<script type="text/javascript">
var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
document.write("<a href='http://www.adobe.com/go/getflashplayer'><img src='"
+ pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>" );
</script>
</div>
Which displays generic message about not having flash.
I know I can put HTML there to be displayed if Flash doesn't exist but I don't want to load the HTML if it's not need (case when Flash is installed) so I thought the best way is to redirect to an HTML page if flash doesn't exist.
How to do that in Flex?
Upvotes: 0
Views: 2149
Reputation: 2454
You won't be able to do this in Flex, since your application won't get loaded if the user doesn't have the correct Flash player version. So your best bet is to modify the index.template.html file. You haven't specified what version of Flex you're using, the template file might be different between versions 4 and 3.
Flex 3 had the following JS code to detect whether or not the user has the good Flashplayer version:
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);
// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if ( hasProductInstall && !hasRequestedVersion ) {
//sniped
} else if (hasRequestedVersion) {
//sniped
} else { // flash is too old or we can't detect the plugin
And it's at this last else that you'd want to insert your JS code to redirect, something like:
window.location.replace('otherpage.html');
Your template file should have something similar to this.
More on JS redirects - http://andylangton.co.uk/articles/javascript/javascript-redirect-scripts/
Flex 4
First disable express install from project properties -> Flex Compiler under HTML wrapper. WARNING: This will overwrite your html-template folder, so all your modifications on those files will be lost. You should get a confirmation popup when you do that.
Then open html-template/swfobject.js in text editor. Go to line 693 - it should be just under "show alternative content" else in function embedSWF - and comment it and add, or just replace it with:
window.location.replace('http://mydomain/noflash.html');
Do a clean build after you save the file.
This is the most straightforward way of doing it. There's also a more elegant way where you don't modify swfobject.js but index.template.html instead, but requires a bit more code written.
Please note that there are certain settings under Flex Compiler that will overwrite your html-template folder, undoing any changes you do to the files within.
Upvotes: 2