Skip to main content
Known Participant
July 22, 2013
Answered

Local Connection Multiple Functions

  • July 22, 2013
  • 1 reply
  • 1911 views

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

This topic has been closed for replies.
Correct answer kglad

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.


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.

1 reply

kglad
Community Expert
Community Expert
July 22, 2013

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){
//

}

Known Participant
July 22, 2013

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

Known Participant
July 22, 2013

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