本地连接状态事件错误
当尝试在本地连接中调用函数时,我间歇性地收到此错误。
Error #2044: Unhandled StatusEvent:. level=error, code=
“已处理”输出:
LocalConnection.send() failed [StatusEvent type="status" bubbles=false cancelable=false eventPhase=2 code=null level="error"]
这是发送信息的代码:
package facebook
{
import flash.events.StatusEvent;
import flash.net.LocalConnection;
public class Leaderboard
{
private var sendLC:LocalConnection = new LocalConnection();
public var leaderboardScores:Object;
public static var LB:Leaderboard;
public function Leaderboard()
{
LB = this;
sendLC.addEventListener(StatusEvent.STATUS, statusError);
}
public function showAbilities():void
{
var abilityArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[3].value];
abilityArray.push(player);
}
abilityArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showAbilities", abilityArray);
showDeaths();
}
public function showDeaths():void
{
var deathArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[4].value];
deathArray.push(player);
}
deathArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showDeaths", deathArray);
showChallenges();
}
public function showChallenges():void
{
var challengeArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[5].value];
challengeArray.push(player);
}
challengeArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showChallenges", challengeArray);
showMoney();
}
public function showMoney():void
{
var moneyArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[6].value];
moneyArray.push(player);
}
moneyArray.sortOn([3], Array.NUMERIC);
trace("! ! ! ! ! !SENDING MONEY ! ! ! ! ! !");
sendLC.send("_myConnection", "showMoney", moneyArray);
showBuffs();
}
public function showBuffs():void
{
var buffArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[7].value];
buffArray.push(player);
}
buffArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showBuffs", buffArray);
showKills();
}
public function showKills():void
{
var killArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[8].value];
killArray.push(player);
}
killArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showKills", killArray);
}
private function statusError(e:StatusEvent):void
{
switch (e.level) {
case "status":
trace( "LocalConnection.send() succeeded");
break;
case "error":
trace( "LocalConnection.send() failed " +e);
break;
}
}
}
}
这是接收代码:
package
{
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.LocalConnection;
import flash.events.Event;
public class Main extends Sprite
{
[Embed(source='../assets/leaderboardOutline.png')]
private var outlineClass:Class;
private var receiverLC:LocalConnection = new LocalConnection()
private var background:Bitmap = new outlineClass;
public function Main():void
{
receiverLC.client = this;
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
try
{
this.receiverLC.allowDomain('*')
this.receiverLC.connect("_myConnection");
trace('!~~~~~LocalConnection SUCCEEDED');
}
catch (error:ArgumentError)
{
trace('!~~~~~~LocalConnection FAILURE');
}
addChild(background);
}
public function showAbilities(scores:Array):void
{
trace("ABILITIES\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showDeaths(scores:Array):void
{
trace("DEATHS\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showChallenges(scores:Array):void
{
trace("CHALLENGES\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showMoney(scores:Array):void
{
trace("MONEY\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showBuffs(scores:Array):void
{
trace("BUFFS\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showKills(scores:Array):void
{
trace("KILLS\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
}
}
我对错误所做的搜索似乎没有什么价值。大多数人说在函数外部声明本地连接可以为他们解决这个问题。任何人都可以看到任何可能导致此错误的内容吗?
I'm getting this error intermittently when attempting to call functions in a localconnection.
Error #2044: Unhandled StatusEvent:. level=error, code=
The "handled" output:
LocalConnection.send() failed [StatusEvent type="status" bubbles=false cancelable=false eventPhase=2 code=null level="error"]
Here is the code that sends the info:
package facebook
{
import flash.events.StatusEvent;
import flash.net.LocalConnection;
public class Leaderboard
{
private var sendLC:LocalConnection = new LocalConnection();
public var leaderboardScores:Object;
public static var LB:Leaderboard;
public function Leaderboard()
{
LB = this;
sendLC.addEventListener(StatusEvent.STATUS, statusError);
}
public function showAbilities():void
{
var abilityArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[3].value];
abilityArray.push(player);
}
abilityArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showAbilities", abilityArray);
showDeaths();
}
public function showDeaths():void
{
var deathArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[4].value];
deathArray.push(player);
}
deathArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showDeaths", deathArray);
showChallenges();
}
public function showChallenges():void
{
var challengeArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[5].value];
challengeArray.push(player);
}
challengeArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showChallenges", challengeArray);
showMoney();
}
public function showMoney():void
{
var moneyArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[6].value];
moneyArray.push(player);
}
moneyArray.sortOn([3], Array.NUMERIC);
trace("! ! ! ! ! !SENDING MONEY ! ! ! ! ! !");
sendLC.send("_myConnection", "showMoney", moneyArray);
showBuffs();
}
public function showBuffs():void
{
var buffArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[7].value];
buffArray.push(player);
}
buffArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showBuffs", buffArray);
showKills();
}
public function showKills():void
{
var killArray:Array = [];
for each (var o:Object in leaderboardScores)
{
var player:Array = [o[0], o[1], o[2], o[8].value];
killArray.push(player);
}
killArray.sortOn([3], Array.NUMERIC);
sendLC.send("_myConnection", "showKills", killArray);
}
private function statusError(e:StatusEvent):void
{
switch (e.level) {
case "status":
trace( "LocalConnection.send() succeeded");
break;
case "error":
trace( "LocalConnection.send() failed " +e);
break;
}
}
}
}
And here is the recieving code:
package
{
import flash.display.Bitmap;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.net.LocalConnection;
import flash.events.Event;
public class Main extends Sprite
{
[Embed(source='../assets/leaderboardOutline.png')]
private var outlineClass:Class;
private var receiverLC:LocalConnection = new LocalConnection()
private var background:Bitmap = new outlineClass;
public function Main():void
{
receiverLC.client = this;
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
try
{
this.receiverLC.allowDomain('*')
this.receiverLC.connect("_myConnection");
trace('!~~~~~LocalConnection SUCCEEDED');
}
catch (error:ArgumentError)
{
trace('!~~~~~~LocalConnection FAILURE');
}
addChild(background);
}
public function showAbilities(scores:Array):void
{
trace("ABILITIES\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showDeaths(scores:Array):void
{
trace("DEATHS\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showChallenges(scores:Array):void
{
trace("CHALLENGES\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showMoney(scores:Array):void
{
trace("MONEY\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showBuffs(scores:Array):void
{
trace("BUFFS\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
public function showKills(scores:Array):void
{
trace("KILLS\n");
try{
for each (var a:Array in scores)
trace("NAME: " + a[1] + " SCORE: " + a[3]);
}
catch (e:Error)
{
trace("Error " + e);
}
}
}
}
The searching I've done on the error seems to be of little value. Most people say that declaring the localconnection outside of the function fixed it for them. Can anyone see anything that could cause this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以看到一些可能存在问题的事情。
首先是流程,您设置的发送方必须在接收方之前加载。由于接收器没有包含在 try/catch 中,因此您不知道它是否实际连接。
接下来是你的状态事件不佳。
最后,您需要让 swf 来回串扰,以便发送者知道另一个 swf 已准备好。
[编辑]
在下面的函数中,您分配了 o[4],但在回调函数中,您正在访问不存在的 o[3]。
除了第一个回调之外的所有回调都受到相同问题的困扰
I can see a few things that might be an issue.
First is the flow the way you have it set up the sender would have to be loaded before the receiver. Since the receiver is not wrapped in a try/catch you have no idea if it actually connected.
Next is that your status events poorly.
And last you need to have the swfs cross talk back and forth so the sender will know the other swf is ready.
[EDIT]
In the following function you are assigning o[4] but in the call back function you are accessing o[3] which doesnt exist.
All but the first of your call backs are plagued with the same issue
传递到本地 swf 的信息过多。如果您需要快速更改数据,请为每个功能创建单独的本地连接。
Too much information is being passed to the local swf. If you need to change the data quickly create separate LocalConnections for each of the functions.