I am having a problem with the FlexGlobals.topLevelApplication. I have five situations:
1) Running in the prjector;
2) Firefox, running the swf directly in the browser;
3) Firefox, running with the swf embedded in a HTML page;
4) IE, running the swf directly in the browser;
5) IE, running with the swf embedded in a HTML page.
The following are the returns of the FlexGlobals.topLevelApplication command:
1) Main0;
2) Main0;
3) Main0;
4) Main0;
5) flexglobals.
The last one looks very, very wrong to me, and it means that I can't get the topLevelApplication in IE when the SWF is embedded in a HTML page (the most common scenerio!). Instead I get either:
1) The value of attributes.id;
2) or if that is not specified, the id of the HTML div that the SWF is enclosed in, which in this case is 'altContent'.
I have tried on 3 different machines all running Windows 7 with the following player versions:
11.4.402.265
11.3.300.265
11.3.300.271
As Application.application is now depreciated and I can't even compile with that at the moment, is there another reliable way to get the topLevelApplication? My application is failing in IE and it seems to be due to the FlexGlobals.topLevelApplication.
The code is using SWFObject which I haven't included.
-- Main.mxml ---
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="onCreationComplete()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
private function onCreationComplete():void {
Alert.show("FlexGlobals.topLevelApplication [" + FlexGlobals.topLevelApplication + "]");
}
]]>
</fx:Script>
</s:Application>
--- index.html ---
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>flexglobals</title>
<meta name="description" content="" />
<script src="js/swfobject.js"></script>
<script>
var flashvars = {
};
var params = {
menu: "false",
scale: "noScale",
allowFullscreen: "true",
allowScriptAccess: "always",
bgcolor: "",
wmode: "direct" // can cause issues with FP settings & webcam
};
var attributes = {
id:"flexglobals"
};
swfobject.embedSWF(
"flexglobals.swf",
"altContent", "100%", "100%", "10.0.0",
"expressInstall.swf",
flashvars, params, attributes);
</script>
<style>
html, body { height:100%; overflow:hidden; }
body { margin:0; }
</style>
</head>
<body>
<div id="altContent">
<h1>flexglobals</h1>
<p><a href="http://www.adobe.com/go/getflashplayer">Get Adobe Flash player</a></p>
</div>
</body>
</html>
Click here and do a File > Download to get the files.
Unzip and look in the bin folder.
The version of IE that I am using is 9.0.8112.16421 (64 bit).
I have uploaded the HTML page here and the SWF can be accessed directly here. I edited my above post to include the IE version, you must have read it before I made the edit.
Unfortunatly this is hosted on my home server which does not have a fixed IP address and does not use a dynamic DNS service hence it goes down quite often. I will try and check it often over the next day or so to try and keep the DNS up. I don't have any other servers available to me at the moment.
I was really looking to be able to access an object in the Application object, but that is due to bad programme design. I will need to redesign it a little as FlexGlobals.topLevelApplication.name doesn't give me what I need.
I have filed a bug report (SDK-32294) but don't have a link as it is incorrectly flagged by the bug tracking system as a potential security issue.
Thanks for your help.
I have now also tried this using an Object tag in a HTML page to load the SWF and I don't have the same issue, the problem only appears to be there using SWFObject and also another JavaScript solution that I found. In your opinion where is the most likely place for the bug to be? It would seem to me that the FlashPlayer should be handling the result of FlexGlobals.topLevelApplication, but the method of adding the SWF to the HTML page seems to have an affect as well. Looking at the FlexGlobals and spark.Application code, there doesn't seem to be any ExternalInterface type calls.
I am asking as I am finding it difficult to work around the issues I am having, and it would be better to find a fix rather than a workaround.
I’m not sure what your goal is. FlexGlobals.topLevelApplication is correctly returning the Main class instance in all browsers. It is only the toString() implied in your Alert test that displays something different on IE. If you need to access any other properties on the application, they will be there in all browsers.
Thanks for putting me straight, you are of course correct and made me look elsewhere for the problem.
In the end it was an issue with calls to error.getStackTrace() in a non-debug version of the FlashPlayer that was installed on IE. I am now checking Capabilities.isDebugger before calling that. I had originally thought that I was not getting the Application object back, but as you say, I am.
Sorry for all the posts and thanks for your help.
North America
Europe, Middle East and Africa
Asia Pacific