A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] LocalConnection question --- can multiple swfs listen to one swf?

  1. #1
    absolutezero3424
    Join Date
    Nov 2006
    Posts
    508

    resolved [RESOLVED] LocalConnection question --- can multiple swfs listen to one swf?

    The question is pretty straightforward: can multiple swfs listen to one swf on the same connection channel? Here's my code:

    SWF A in AS3:
    Code:
    sendToTest.send("sendToTest", "resetForm");
    SWF B in AS2:
    Code:
    var receiveFromCourse:LocalConnection = new LocalConnection();
    receiveFromCourse = new LocalConnection();
    
    receiveFromCourse.resetForm = function() {
    	setMCCheckState("reset");
    	router.buttonFlag = false;
    	router.resetFlag = false;
    	router.checkFlag = false;	
    	router.initControlButton(onMCButton);
    	router.sessionStart();
    	setMCAssets();	
    }
    
    receiveFromCourse.client = this;
    
    try {
    	receiveFromCourse.connect("sendToTest");
    } catch (e) {
    	trace("Can't connect...the connection name is already being used by another SWF");
    }
    ...and SWF C, D, E, etc. are coded JUST LIKE SWF B. When I execute this code, SWF B does it's thing, but C, D, E, etc. do not. I'm thinking that this won't work because it's the same channel, but how inefficient is that!!! Do I have to create separate channels for each receiving SWF? That's dumb! Additionally, do I need multiple LocalConnection object to get this done, or can I do it all thru one LC, in this case "sendToTest"? For example,

    Code:
    sendToTest.send("sendToTestB", "resetForm");
    sendToTest.send("sendToTestC", "resetForm");
    sendToTest.send("sendToTestD", "resetForm");
    ...
    thoughts???

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Only the most recent swf to connect will receive calls on that channel.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  3. #3
    absolutezero3424
    Join Date
    Nov 2006
    Posts
    508
    Quote Originally Posted by neznein9 View Post
    Only the most recent swf to connect will receive calls on that channel.
    thanks for the response...do you know a way around this? I've tried multiple approaches and none have worked thus far. You see what I'm trying to accomplish.

    I've tried creating a new LocalConnection object for each and I've tried using the same LC and just sent messages on different channels...both have failed. Not sure why? What's the correct way to do this? Thx!

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Set up a channel that's just for registering new connections. When you launch a new swf, generate a random string that you send to the controller swf - that will be the name of the channel to communicate with that unique swf. After the initial handshake on the generic channel - use the unique channel to talk to that swf from there on out.

    If you need to talk to a bunch of swfs at once, just keep an array of those different channels and loop through them with your command.
    Please use [php] or [code] tags, and mark your threads resolved 8)

  5. #5
    absolutezero3424
    Join Date
    Nov 2006
    Posts
    508
    ok, I've solved my own dilemma...I had a spelling error (doh!). The previous suggestion of using the same LC and different channel names works fine!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center