作者: | 来源:互联网 | 2023-09-23 08:04
ImlookingtograbcookievaluesforthesamedomainwithinaFlashmovie.Isthispossible?我想在Fla
I'm looking to grab COOKIE values for the same domain within a Flash movie. Is this possible?
我想在Flash电影中抓取同一个域的COOKIE值。这可能吗?
Let's see I let a user set a variable foo and I store it using any web programming language. I can access it easily via that language, but I would like to access it via the Flash movie without passing it in via printing it within the HTML page.
让我们看看我让用户设置变量foo并使用任何Web编程语言存储它。我可以通过该语言轻松访问它,但我希望通过Flash电影访问它,而不通过在HTML页面中打印它来传递它。
7 个解决方案
11
If you just want to store and retrieve data, you probably want to use the SharedObject class. See Adobe's SharedObject reference for more details of that.
如果您只想存储和检索数据,则可能需要使用SharedObject类。有关详细信息,请参阅Adobe的SharedObject参考。
If you want to access the HTTP COOKIEs, you'll need to use ExternalInterface to talk to Javascript. The way we do that here is to have a helper class called HTTPCOOKIEs.
如果要访问HTTP COOKIE,则需要使用ExternalInterface与Javascript通信。我们这样做的方法是有一个名为HTTPCOOKIEs的帮助器类。
HTTPCOOKIEs.as:
import flash.external.ExternalInterface;
public class HTTPCOOKIEs
{
public static function getCOOKIE(key:String):*
{
return ExternalInterface.call("getCOOKIE", key);
}
public static function setCOOKIE(key:String, val:*):void
{
ExternalInterface.call("setCOOKIE", key, val);
}
}
You need to make sure you enable Javascript using the 'allowScriptAccess' parameter in your flash object.
您需要确保使用flash对象中的'allowScriptAccess'参数启用Javascript。
Then you need to create a pair of Javascript functions, getCOOKIE and setCOOKIE, as follows (with thanks to quirksmode.org)
然后你需要创建一对Javascript函数,getCOOKIE和setCOOKIE,如下所示(感谢quirksmode.org)
HTTPCOOKIEs.js:
function getCOOKIE(key)
{
var COOKIEValue = null;
if (key)
{
var COOKIESearch = key + "=";
if (document.COOKIE)
{
var COOKIEArray = document.COOKIE.split(";");
for (var i = 0; i 一旦你的flash项目中有HTTPCOOKIEs.as,并从你的网页加载了HTTPCOOKIEs.js,你就可以从你的flash影片中调用getCOOKIE和setCOOKIE来获取或设置HTTP COOKIE。
This will only work for very simple values - strings or numbers - but for anything more complicated you really should be using SharedObject.
这只适用于非常简单的值 - 字符串或数字 - 但对于任何更复杂的事情,您确实应该使用SharedObject。