Skip to main content
Participating Frequently
June 12, 2007
Question

globals in crossdomain swf's (AS2)

  • June 12, 2007
  • 7 replies
  • 732 views
Hi,

I have two domains (on the same server) each of the domains contains a crossdomain xml and swf's. The swf's have System.security.allowDomain("*") set.
From 'domainOne' I start the main swf. This main swf loads (with a loader component) a swf from 'domainTwo'. So var so good.
In the main swf on 'domainOne' I have some _global functions. When I call these global functions from the second swf (from 'domainTwo') nothing happens.

My question: Is it possible to call global functions between crossdomain swf's? If so, what's the trick?

Thanks
This topic has been closed for replies.

7 replies

kglad
Community Expert
Community Expert
June 13, 2007
if you couldn't get it to work using a path to the function you either are using an incorrect path or you're trying to access the function before it's defined.
kglad
Community Expert
Community Expert
June 12, 2007
ok.
Participating Frequently
June 13, 2007
Hi kglad,

I cannot get it to work. Even with a direct path from _root to the contentHolder.
I think that the only solution left is to put all content in one domain and with a frameSet which will load the content from the main domain. Is not a good solution but for now one that works.

I hope that someone (maybe from Adobe) could give the right solution. I think crossdomain setups are very handy but than they have to consistent with all levels. Thus also _globals.

Anyway, thanks kglad for your help.
kglad
Community Expert
Community Expert
June 12, 2007
i didn't know about that article.

try prefixing your function call from swf 2 with the path/movieclip timeline that contains your function.
Participating Frequently
June 12, 2007
I think thats about the only thing left. I'll try.
I'll let you know if it works.

Thanks!
kglad
Community Expert
Community Expert
June 12, 2007
that looks ok. i don't think you're failing to call MenuActie from your 2nd swf.
Participating Frequently
June 12, 2007
I have found something that could be the problem:
http://www.adobe.com/devnet/flash/articles/fplayer_security_04.html

It says:
quote:

When two movies are from different domains, Macromedia Flash Player ensures that the two movies have different copies of the ActionScript global object. The global object is usually implicitly referenced. For example, all objects in the Macromedia Flash Player standard library, such as MovieClip, Array, and so forth, are part of the global object. The global object also holds global variables created by assigning properties to _global. Separating global objects between movies from different domains has occurred since Macromedia Flash Player 6. However, Macromedia Flash Player 7 introduces a new restriction: movies made for Macromedia Flash Player 6 or earlier can never share a global object with movies made for Macromedia Flash Player 7 or later, even when the movies are from the same exact domain and protocol. This may have subtle repercussions for sites that mix movies made for Macromedia Flash Player 6 and 7.


But I find this very stange, especially if you use System.security.allowDomain(); this should grant the swf access. Or am I wrong here? (I only use player 8 files, thus no mixed ones)

Any ideas?
kglad
Community Expert
Community Expert
June 12, 2007
copy and paste your function's definition, your load statement and the code you use to call your function.
Participating Frequently
June 12, 2007
Some of the code from the main swf (domainOne):

// INIT
System.security.allowDomain("*");
import mx.controls.Alert;

// FUNCTION
_global.MenuActie = function(actie:String) {
if (actie == undefined) {
var msg:String = "Het gekozen menuitem is niet aanwezig of niet te gebruiken.";
msg += " Neem contact op met uw beheerder.";
var titel:String = "ERROR:";
Alert.show(msg,titel,Alert.OK);
} else if (actie=="Empty" or actie=="Login") {
if (_global.ActiveScreen == "FactuurManagement") {
content_lo.contentPath = "FacturatieModule/FM.swf";
} else if (_global.ActiveScreen == "LayoutManagement") {
content_lo.contentPath = "LayoutModule/LM.swf";
} else {
content_lo.contentPath = "CONTENT/"+actie+".swf";
};
} else {
content_lo.contentPath = _global.baseURL + actie+".swf";
};
Progress(content_lo);
content_lo.load();
};


Some of the code from the second swf (domainTwo):

// INIT
System.security.allowDomain("*");

// FUNCTIONS
mbListener.change = function(evt_obj:Object) {
var menuItem_obj:Object = evt_obj.menuItem;
MenuActie(menuItem_obj.attributes.instanceName);
};
menu_mb.addEventListener("change", mbListener);
kglad
Community Expert
Community Expert
June 12, 2007
and is there any problem?
Participating Frequently
June 12, 2007
ow I'm sorry.

I meant to say that I have the code like you said. I didn't change anything so the problem stil exists.
kglad
Community Expert
Community Expert
June 12, 2007
just use the function name. do not prefix with _global.
Participating Frequently
June 12, 2007
Hi kglad,

Thanks for your reply. When I call the global function from the second swf I do use the name without _global; like: myFunct();