13 Replies Latest reply on Jul 25, 2013 7:05 AM by kglad

    Local Connection Multiple Functions

    copperstick

      Hello,

       

      I have two exe files and I am trying to control one with the other in two different windows (Sender / Reciever Windows)

       

      I am doing this in AS2 simply because the original set-up (single screen set-up now they want a second screen) was done awhile back in AS2 and I didn't want to recreate it...

       

      I got the first function to work but can't get the second function to work and I don't know why...new to local connection function so obviously I am missing something.

       

      I am doing the Code in one frame on its own layer to control all buttons on one LocalConnection:

       

      Sender Code:

       

      sending_lc = new LocalConnection();

      mybtn1.onRelease = function() {
      sending_lc.send("my_lc_as2", "execute_this", gotoAndPlay(2));
      }

       

      mybtn2.onRelease = function() {
      sending_lc.send("my_lc_as2", "execute_this", gotoAndPlay(4));
      }

       

      Reciever Code:

       

      receiving_lc = new LocalConnection();

       

      receiving_lc.execute_this = function(){
          gotoAndPlay(2);

      }

      receiving_lc.connect("my_lc_as2");

       

       

      receiving_lc.execute_this = function(){
          gotoAndPlay(4);

      }

      receiving_lc.connect("my_lc_as2");

       

       

      In essence I am trying to get buttons (6 in total) on Sender to forward the reciever to a new frame on release. The button "mybtn1" is working and sending the reciever movie to frame 2. The button "mybtn2" however does nothing and I am obviously not putting this together correctly. Any ideas? Help? Please?

       

      chris

        • 1. Re: Local Connection Multiple Functions
          kglad Adobe Community Professional & MVP

          you only need one function.  try:

           

           

          Sender Code:

           

          sending_lc = new LocalConnection();

          mybtn1.onRelease = function() {
          sending_lc.send("my_lc_as2", "gotoF", 2);
          }

           

          mybtn2.onRelease = function() {
          sending_lc.send("my_lc_as2", "gotoF", 4);
          }

           

          Reciever Code:

           

          receiving_lc = new LocalConnection();

           

          receiving_lc.gotoF= function(n:Number){
              gotoAndPlay(n);

          }

          receiving_lc.connect("my_lc_as2");

           

           

           

          if you want to use a 2nd function use:

           

          //send

          sending_lc.send("my_lc_as2", "secondF", params);

           

          //receive

          receiving_lc.secondF= function(params){
          //

          }

          • 2. Re: Local Connection Multiple Functions
            copperstick Level 1

            Thanks kglad,

             

            I now have exactly this code on the first frame (only key frame on its own layer) of the sender:

             

            //

             

            sending_lc = new LocalConnection();

            mybtn1.onRelease = function() {
            sending_lc.send("my_lc_as2", "gotoF", 2);
            }


            mybtn2.onRelease = function() {
            sending_lc.send("my_lc_as2", "gotoF", 4);
            }

             

            //

             

            and this code code on the reciever (only keyframe on its own layer):

             

            //

             

            receiving_lc = new LocalConnection();

            receiving_lc.gotoF = function(n:Number){
                gotoAndPlay(n);

            }

            receiving_lc.connect("my_lc_as2");

             

            //

             

            The first button "mybtn1" works just fine but the second one "mybtn2" still doesnt forward the reciever to frame 4

             

            any ideas?

             

            To clarify. this is a simulation. when someone pushes a button (the only active button on the screen, mybtn1 to start with), both the sender and reciever are going to forward to a new frame, play an animation and the user will then be presented with a new button (mybtn2) to push which will, again, forward to a new frame and play an animation until the user has completed the cycle (6 buttons).

             

            Once I put this new code in, the

             

            on (release) {

            gotoAndPlay(2);

            }

             

            code I have placed on all the buttons no longer works for btn1 (the only button where the lc code is working) so the sender no longer progresses to the new frame...but that is less of a problem than getting the second button (mybtn2) working...the code for btn2 (attached to the button) still works. So the button code on btn1 (which IS forwarding the reciever to the new frame) doesn't work with this new code, but btn2 which ISNT forwarding the reciever to the new frame, does still work.

             

            Sorry to be bother, I am just a bit frustrated....Thanks for any further suggestions you might be able to offer. I hope I am being clear with what I am trying to do and what my issue is.

             

            Chris

            • 3. Re: Local Connection Multiple Functions
              copperstick Level 1

              I know its probably not the best way but when I had my original code in it, it was forwarding to the new frame on the reciever AND forwarding to the new frame on the sender with the gotoAndPlay code on the button.

               

              Just because I need to get this done and have little interest in doing it in the most effeciant way possible.

               

              Is it possible to simply make a keyframe on the code layer every time there is a button that needs to be used and call out a new local connection for each button individually as they come up?

               

              so just use this code:

               

              Sender:

               

              sending_lc = new LocalConnection();

              mybtn1.onRelease = function() {
              sending_lc.send("my_lc_as2", "execute_this", gotoAndPlay(2));
              }

               

              Reciever:

               

              receiving_lc = new LocalConnection();

               

              receiving_lc.execute_this = function(){
                  gotoAndPlay(2);

              }

              receiving_lc.connect("my_lc_as2");

               

               

              on a keyframe in the code layer above the keyframe with each button1

               

              The code above works for btn1 but I can make the code work by calling out a new local connection for button two, three and four...

               

              thanks

              • 4. Re: Local Connection Multiple Functions
                kglad Adobe Community Professional & MVP

                go back to this code but add a trace to confirm you're actually clicking mybtn2:

                 

                 

                sending_lc = new LocalConnection();

                mybtn1.onRelease = function() {
                sending_lc.send("my_lc_as2", "gotoF", 2);
                }


                mybtn2.onRelease = function() {

                trace(this+" clicked");
                sending_lc.send("my_lc_as2", "gotoF", 4);
                }

                 

                //

                 

                and, to this code code on the receiver, add a trace

                 

                //

                 

                receiving_lc = new LocalConnection();

                receiving_lc.gotoF = function(n:Number){

                trace("received "+n);
                    gotoAndPlay(n);

                }

                receiving_lc.connect("my_lc_as2");

                 

                //

                // click your mybtn1 and mybtn2 and report the trace output in each swf.

                1 person found this helpful
                • 5. Re: Local Connection Multiple Functions
                  copperstick Level 1

                  When I run the trace and hit btn1 the reciever forwards but the sender does not.

                   

                  I get "received 2" in output.

                   

                  I have to right click forward the sender to the frame with the next button.

                   

                  I hit btn2 and I get nothing in the output.

                   

                  Thanks

                  • 6. Re: Local Connection Multiple Functions
                    kglad Adobe Community Professional & MVP

                    when you click mybtn2, do you see something like

                     

                    _root.mybtn2 clicked when testing the send fla in flash?

                     

                    if not, you're not clicking mybtn2.  ie, check the object's instance name that you think is mybtn2.

                     

                    and, i don't know what you mean by the sender going anywhere.  there's no code to change any frame in the sender.

                    • 7. Re: Local Connection Multiple Functions
                      copperstick Level 1

                      I checked the instance name under properties for both buttons and in the field called 'instance name' is mybtn1 and mybtn2 (as they are in the code as well)...under it says Instance of: pmvopen and pwvopen which are the names of the buttons themselves...

                       

                      I have the code:

                       

                      on (release) {

                      gotoAndPlay(3);

                      }

                       

                      attached to all the buttons so that the sender will forward to a new frame when the reciever forwards.

                       

                      Both the LC code and the code attached to mybtn1 worked before but mybtn2 didn't work at all . I changed it to the new code...now mybtn1 forwards the reciever but not the sender and mybtn2 forwards the sender but not the reciever (and I am getting no output for the mybtn2).

                       

                      Both Sender and reciever needs to go to a new frame when the buttons are pushed...

                       

                      the code I have right now on the sender is:

                       

                      sending_lc = new LocalConnection();

                      mybtn1.onRelease = function() {
                      sending_lc.send("my_lc_as2", "gotoF", 2);
                      }


                      mybtn2.onRelease = function() {
                      trace(this+" clicked");
                      sending_lc.send("my_lc_as2", "gotoF", 4);
                      }

                       

                      This is on a keyframe at the beginning of the time line on its own layer

                       

                      the code I have right now on the reciever is:

                       

                      receiving_lc = new LocalConnection();

                      receiving_lc.gotoF = function(n:Number){
                      trace("received "+n);
                          gotoAndPlay(n);

                      }

                      receiving_lc.connect("my_lc_as2");

                       

                      also on its own layer in the first keyframe of that layer.

                       

                      Each button has:

                       

                      on (release) {

                      gotoAndPlay(3);

                      }

                       

                      attached to it to forward the sender to a new frame

                       

                      Sorry...this has me completely frustrated. Thanks for trying to help.

                      • 8. Re: Local Connection Multiple Functions
                        copperstick Level 1

                        Oh, I am not sure if I am doing things right with the tracer. Since I need two windows open to do this I have both sender and reciever open...hit ctrl enter on both. When I hit mybtn1 I get the message 'recieved 2' and nothing else.

                         

                        When I forward to the frame that has btn2 and hit it...I get nothing at all.

                        • 9. Re: Local Connection Multiple Functions
                          kglad Adobe Community Professional & MVP

                          no object should have code attached to it.

                           

                          remove all those on(release) statements.

                           

                          retest mybtn2 and see if you can get the trace working.  if you can't you don't have an object named mybtn2 that exists when that code exits or, you're not clicking mybtn2.

                          • 10. Re: Local Connection Multiple Functions
                            copperstick Level 1

                            I removed all the code attached to the buttons and it still didn't work.

                             

                            I guess I thought that if I had the code on its own layer in a single keyframe at the start then that code would still affect all buttons down the timeline. This didn't seem to be the case.

                             

                            The first button was working because it started on a key frame that was in the same location as the code keyframe. I had to cut and paste the code from that key frame, make another code keyframe above the frame that had mybtn2 on it and then it started woking so it seems everytime there is a button that needs this code I need to have a code keyframe to go with it.

                             

                            Although the reciever code seems to be working on just the one keyframe on the code layer. It may have to do with the fact that the buttons are not all on the stage at the same time, they appear only in the framed they are needed.

                             

                            So both buttons are working and the output reads:

                             

                            received 2

                            _level10.mybtn2 clicked

                            recieved 4

                             

                            So now I just need to do this for all my buttons.

                             

                            One last question and I think I might be able to take it from here:

                             

                            If I want the sender to change to a new frame as well, how to I add that code since I cant put it on the button anymore...

                             

                            So when I push the mybtn1 it will send the reciever to frame 2 and the sender to frame 2 as well? Push mybtn2 and it will send the sender and the reciever to frame 4, etc...

                             

                            I gotta say, I really appreciate the help you have given me here, I feel a bit less frustrated with now and how this works seems a bit more clear to me. Thanks

                            • 11. Re: Local Connection Multiple Functions
                              kglad Adobe Community Professional & MVP

                              you're welcome.

                               

                              and, add code to the button handler if you want the sender swf to do something when mybtn2 is released

                               

                              mybtn2.onRelease = function() {

                              this._parent.gotoAndStop(whatever);

                              sending_lc.send("my_lc_as2", "gotoF", 4);

                              }

                              1 person found this helpful
                              • 12. Re: Local Connection Multiple Functions
                                copperstick Level 1

                                You sir are saint....I still have pause, stop, foward and back buttons to do but I believe I can handle those now...if not you might see me again for one last round but my main buttons are operating perfectly and running in unison. Thanks again.

                                • 13. Re: Local Connection Multiple Functions
                                  kglad Adobe Community Professional & MVP

                                  you're welcome.