Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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.

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

Next is that your status events poorly.

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

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.

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

All but the first of your call backs are plagued with the same issue

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top