Flash“这部电影中的脚本” - 由loadVars或setInterval引起的?
这有点奇怪...
我有一个加载外部 SWF 的 Flash 文件。在那里,我使用 LoadVars 从服务器获取外部数据。当数据到达时,我使用 setInterval 来调用淡入内容的函数。
到目前为止,一切都很好。
但是,当我在所有数据到达之前切换菜单(也称为卸载一部电影以加载另一部电影)时,Flash 会挂起大约 15 秒,然后向我显示臭名昭著的消息“这部电影中的脚本正在减慢 Flash - 你想中止吗?”它?” (粗略翻译)。
我在 SWF 中附加了一个“onUnload”函数,这导致了主要问题,其中我使用clearInterval 来消除间隔并重新实例化 LoadVars 变量。
没有任何帮助...
有什么想法吗?
根据请求 - 这是导致问题的 SWF 的来源:
var myTimer = null;
var server_send:LoadVars = new LoadVars();
this.onUnload = function () {
clearInterval(myTimer);
server_send = new LoadVars();
trace("stopping gewerbe");
};
var myself = scrollContent;
import JSON; // external Class for parsing JSON
var sRes:LoadVars = new LoadVars();
function fadeIn(which){
which._alpha += 3;
if(which._alpha >= 100){
clearInterval(myTimer);
}
}
sRes.onLoad = function(success:Boolean){
if (success){
var o:Object = JSON.parse(sRes.res);
var s:String = JSON.stringify(o);
//trace(sRes.res);
var y = 0;
for(item in o){
actCol = 0;
myself.attachMovie("row", "entry" + item, myself.getNextHighestDepth(), {_x: 0, _y:y});
var tr = myself["entry" + item];
tr.cTitle = o[item]["title"];
tr.cBild = o[item]["image"];
tr.cText = o[item]["text"];
y += 65;
}
myTimer = setInterval(fadeIn, 0.1, myself);
_root.myIntervals.push(myTimer);
}
else
{
trace("no connection...");
}
}
myself._alpha = 0;
var vars = Array("id");
var values = Array("3");
server_send.load('void.txt');
for(var i=0;i<vars.length;i++)
{
server_send[vars[i]] = escape(values[i]);
}
server_send.sendAndLoad(_global.server, sRes, "POST");
stop();
This is someting weird...
I have a Flash-file that loads external SWFs. There I use LoadVars to get external data from a server. When the data has arrived, I'm using setInterval to call a function that fades-in the content.
So far so good.
But when I switch menus (a.k.a. unload one movie to load another) before all the data has arrived, Flash hangs for like 15 seconds and then shows me the infamous message «A script in this movie is slowing down Flash - would you like to abort it?» (roughly translated).
I attached an «onUnload»-function to the SWF that causes the major problems, where I use clearInterval to get rid of the interval and re-instantiate the LoadVars-Variable.
Nothing helps...
Any ideas?
as per request - here's the source of the SWF causing the trouble:
var myTimer = null;
var server_send:LoadVars = new LoadVars();
this.onUnload = function () {
clearInterval(myTimer);
server_send = new LoadVars();
trace("stopping gewerbe");
};
var myself = scrollContent;
import JSON; // external Class for parsing JSON
var sRes:LoadVars = new LoadVars();
function fadeIn(which){
which._alpha += 3;
if(which._alpha >= 100){
clearInterval(myTimer);
}
}
sRes.onLoad = function(success:Boolean){
if (success){
var o:Object = JSON.parse(sRes.res);
var s:String = JSON.stringify(o);
//trace(sRes.res);
var y = 0;
for(item in o){
actCol = 0;
myself.attachMovie("row", "entry" + item, myself.getNextHighestDepth(), {_x: 0, _y:y});
var tr = myself["entry" + item];
tr.cTitle = o[item]["title"];
tr.cBild = o[item]["image"];
tr.cText = o[item]["text"];
y += 65;
}
myTimer = setInterval(fadeIn, 0.1, myself);
_root.myIntervals.push(myTimer);
}
else
{
trace("no connection...");
}
}
myself._alpha = 0;
var vars = Array("id");
var values = Array("3");
server_send.load('void.txt');
for(var i=0;i<vars.length;i++)
{
server_send[vars[i]] = escape(values[i]);
}
server_send.sendAndLoad(_global.server, sRes, "POST");
stop();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新
首先,我建议您放弃使用 setInterval,它们特别有问题。而是使用
Timer
类,它的管理和使用要简单得多。不过,
sRes.onLoad
函数内的setInterval
可能是您的问题。间隔应以毫秒为单位,因此您的 0.1 可能应为 100(1/10 秒),并且fadeIn
和unLoad
中的clearInterval
调用> 可能有myInterval
超出范围,请使用trace
检查它们以确保它们按预期清除。代码
好吧,我已经重新排序了代码以使其更具可读性......但是,它的形状仍然很糟糕。我正在标记需要与您进一步讨论的内容...(请参阅下面代码中的其他注释。)
Update
First off I'd suggest you drop the use of setInterval, they're particularly problematic. Instead use the
Timer
class, which is far more straightforward to manage and use.The
setInterval
inside thesRes.onLoad
function is probably your issue though. The interval should be in milliseconds, so your 0.1 should probably be 100 (for 1/10th second), and theclearInterval
calls infadeIn
andunLoad
might havemyInterval
out of scope, check these with atrace
to make sure they are clearing as expected.Code
Ok, I've re-ordered the code to make it a bit more readable... However, it is still in very bad shape. I'm marking things out that I'd need to discuss with you further... (see below additional comments in the code.)
感谢您的帮助 - 似乎我发现了这个怪癖...
即使电影被卸载,sendAndLoad-response 仍然被调用,似乎导致了循环。
我所做的是:
在脚本顶部添加一个名为“doParse”的变量并将其设置为 true
然后在卸载函数中,我将此 var 设置为 false:
如果数据到达时被调用,我添加了这个:
这有帮助,消息消失了。
Thanks for the help - seems like I found the quirk...
The sendAndLoad-response was still called, even when the movie was unloaded, causing a loop, it seems.
What I did is:
added a variable at the top of the script called «doParse» and set it to true
Then in the unload-function, I set this var to false:
and in the event that gets called when the data arrives, I added this:
This helped and the message disappeared.