LocalConnection StatusEvent错误

时间:2012-01-18 05:32:10

标签: actionscript-3 localconnection

尝试在localconnection中调用函数时,我间歇性地收到此错误。

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);
        }
    }
}   
 }

我对错误所做的搜索似乎没什么价值。大多数人都说,在函数之外声明局部连接会为它们修复它。任何人都可以看到任何可能导致此错误的内容吗?

2 个答案:

答案 0 :(得分:1)

我可以看到一些可能存在问题的事情。

首先是您设置的方式流程,发送方必须在接收方之前加载。由于接收器没有包含在try / catch中,因此您不知道它是否实际连接。

private function connect( ):void{
  try {
    this.receiverLC.allowDomain('*')
    this.receiverLC.connect("_myConnection");
    trace('LocalConnection SUCCEEDED')
  } catch (error:ArgumentError) {
    trace('LocalConnection FAILURE')
  }
}

接下来是你的状态事件很糟糕。

private function statusError(e:StatusEvent):void {
  switch (e.level) {
    case "status":
      trace( "LocalConnection.send() succeeded");
      break;
    case "error":
      trace( "LocalConnection.send() failed " );
      break;
  }
}

最后你需要来回交换swfs,以便发送者知道其他swf准备就绪。



[编辑]
在以下功能中,您将分配o [4],但在回调功能中,您正在访问o [3],但不存在。

    public function showDeaths():void
    {
        var deathArray:Array = [];
        for each (var o:Object in leaderboardScores)
        {

// here is one problem o[4] in showDeaths you are looking for 3
            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();
    }

除了第一个回拨之外,其他所有回复都存在同样的问题

答案 1 :(得分:0)

太多信息传递给本地swf。如果需要快速更改数据,请为每个功能创建单独的LocalConnections。