6 Replies Latest reply on Jan 2, 2010 11:51 PM by Jason Villmer


    Jason Villmer Level 1

      The question relates to having multiple (unique) LocalConnection objects:


      I have a Flash Builder 4 Beta 2 project that uses localConnections to send and receive commands between multiple swf files. Each swf file is loaded into the master Flex application through a standard Loader object.


      Now, the issue is creating multiple localConnections to multiple swf files. I can successfully load a single swf file, establish a localConnection to it and broadcast data (continually from a Event.ENTER_FRAME function). I want the loaded swf to receive consistent data (such as a video's playheadTime).


      So, one works just fine. However, when I want to load 2 swf files and broadcast data (continually) the speed drops tremendously slow. I can successfully create the multiple connections (using a single localConnection or creating individual, unique localConnections) - but the speed drops to nothing.


      So, the question is how do I create multiple localConnections so that the main Flex application can broadcast data (continually) to different swf files (loaded via Loader objects).


      I have tried a significant number of things, including the creation of individual (unique) localConnections that would send data to each swf file on a specific channel. That works but (again) the speed drops to practically nothing. Meaning if more than 2 swf files are receiving data it isn't fast. There are large delays between updates (even after the _sender object has sent data.



          David_F57 Level 5



          This is just a thought, if you have an object that is updated in the main app then when the sub apps initialise they use objectproxy to listen for the changes to the update object.


          This might work I haven't really tried it but I read somewhere that objectproxy was like binding only better.



            David_F57 Level 5

            One other thing, I found in many instances that enterframe in flex is a real shocker as far as resources go much better to use a timer, or try locking the frame rate down to 25fps.

              Jason Villmer Level 1

              Hi David_F57,


              The objectProxy looks interesting. I'll look into it. For now, here's a description of what's going on. ( I hope I can explain it clearly)


              Basically I've got the main application which loads other swf file inside it. The main app has two localConnections, a "_receiver" for receiving commands and a "_sender" for sending commands (to the loaded swf files)


              Now, each loaded swf file also contains it's own sender and receiver localConnections. When the swf is first loaded into the main application, it sends a command telling the main application to start broadcasting information to it.


              Inside the main application is an array, called broadcast. The array holds an array of strings. Each time a swf file is loaded, the swf file sends a command to the main application to add another string to the array. This string is the name of the receiver localConnection inside each swf file. (each string is unique).


              Each time a EVENT.ENTER_FRAME event is fired (in the main app), it calls a function to cycle through each string (swf receiver) and broadcast information to a function inside it.


              1. So, let's go through this one more time. In the main application we have two localConnections and an array:


              internal var _receiver:LocalConnection = new LocalConnection(); // for receiving commands from other swf files

              internal var _sender:LocalConnection = new LocalConnection(); // for broadcasting information (to a function in each swf file)

              internal var broadcast:Array=new Array()  // holds the name of each swf file receiver for which to broadcast


              2. Inside a loaded swf files is this:


              import flash.net.LocalConnection;

              // create a sender connection to send commands

                   var sender:LocalConnection = new LocalConnection( );

                   sender.addEventListener(StatusEvent.STATUS, function(){})

              // create a receiver connection to receive information from main application

                   var receiver:LocalConnection = new LocalConnection();

                   receiver.addEventListener(StatusEvent.STATUS, function(){})

                   receiver.connect( "myReceiver" ) // each swf file requires a unique receiver name

                   receiver.client = this;

              // tells Lucid Viewer to start broadcasting to your receiver

                   sender.send( "_lucidChannel", "_broadcast", "myReceiver")

              // add the function to receive broadcasted information from main application

                   function lucidInfo(time:Number):void{

                   myTextField.text=String(time) }


              3. After the swf file is loaded, it runs the line: sender.send( "_lucidChannel", "_broadcast", "myReceiver")


              4. The main application has the _broadcast function that receives the request (with the broadcast name)

              public function _broadcast(channel:String):void {broadcast.push(channel)}

              The _broadcast function pushes the channel name to the broadcast array.


              5. The main application has a function called broadcasts that is called every frame:

              addEventListener(Event.ENTER_FRAME, broadcasts)


              The function cycles through each of the receiver names in the array and broadcasts information:

              internal function broadcasts(e:Event):void{

              for each(var i:String in broadcast){ _sender.send(i, "lucidInfo", Math.round(flv.playheadTime)) }







              This works perfectly well when there is one swf loaded. When I have two or more, the speed of the updates drops (becomes very slow)

              I have tried replacing the addEventListener(Event.ENTER_FRAME, broadcasts) with a Timer-based method but the same slowness persists.


              I have also tried creating UNIQUE _senders in the hopes that having dedicated senders (per swf) would resolve this. However, it just seems Flash Builder 4 is capable of only really handling ONE outbound localConnection. Anything more than one just breaks down.



              Any thoughts from here would be greatly appreciated