A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Adapting a LocalConnect

  1. #1
    Junior Member
    Join Date
    Dec 2002
    Posts
    12

    Adapting a LocalConnect

    Back again.

    I would like to use the LocalConnect method as described in this tutorial so that instead of the buttonInstance.onRelease sending the contents of userMessage.text to the function in the incoming.fla, I would like to trigger a 'Go to and Play frame 2' that would result in an animation and reset in that .fla.

    Can anybody give me any pointers on what I need to do to adapt the tutorial to use a button that triggers a frame jump instead of a transfer of text? This is related to an earlier question I posted, and i'd still Like to have 'a.swf' trigger an animation in 'b.swf' by using the LocalConnect method.

    I went therough the tutorial above, and made that work, but I'm not sure what code pieces I have to play with to change it. I was going to try something, but it was apparent that it wouldn't work.

    Thanks in advance.

    . . .
    R_S

    I checked out this thread here but I'm sad to say that I'm a bit lost nonetheless. I sort of need a real layman's tutorial for some parts, because I'm finding it hard to work with the actionscripting. it's not like C++ was... Oh, and for the record, I suck at coding.
    Last edited by Rico_Stallion; 12-03-2002 at 09:45 PM.

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    Were you able to download my source files (from the other thread)? Sometimes angelfire can be touchy about allowing people to download the fla files, if you have a problem I can email you a copy. Anyway i'll try to go through some of the code in them, hopefully that will help too

    In the movie that is being controlled from the other movie add these actions,

    recLC = new LocalConnection();
    recLC.pickFrame = function(frame) {
    _root.gotoAndStop(frame);
    };
    recLC.connect("myLC");
    stop();

    okay, so what is this doing?
    First a new variable recLC is created, this is an instance of the local connection object. Next we define a method of the object (that is something the object can do) in this case we name the method pickFrame and it will send the main timeline to the frame of our choice, this frame (number or label) will be supplied by the movie that is controlling it.
    Finally we use the connect method of the local connection object to connect to a local connection named myLC

    in the movie you use to control the above movie we add some code to create the connection as follows, (responds to a button press)

    on (release) {
    sendLC = new LocalConnection();
    sendLC.send("myLC","pickFrame",Math.ceil(Math.rand om() * 5));
    delete sendLC;
    }

    again we use the local connection constructor to create a new instance of the local connection object, calling this one sendLC, we can use the send method of the local connection to object to send out some information. The send method takes some parameters, the name of the connection we will create here this is myLC, remember in the recieving movie it was trying to connect to a local connection called myLC (you can call it anything you like, just sure voth movies use the same name ) the second thing we need to pass the send method is what we want the recieving movie to do when it makes the connection. This is a string containing the name we gave our method of the local connection object in the recieving movie (remember a method is something that does something). so by using the string "pickFrame" as the 2nd parameter passed to the send method flash will try to execute a method of the recieving local connection object named pickFrame. The final parameter passed to send in this case is a random number from 1 to 5, this value will be used as the parameter in the pickFrame method in the recieving movie so for example using

    sendLC.send("myLC","pickFrame",2); // [edit]oops, just noticed a typo I had 2 closing brackets

    would pass the the value 2 as the parameter for the pickFrame method in the recieving movie, this method uses the parameter as the parameter (frame number) in flash's own gotoAndPlay so by doing this we can control the frame number the movie plays from.

    once we have used the local connection object in the sending movie, for the sake of neatness we delete it.

    Hope this helps
    Last edited by catbert303; 12-05-2002 at 09:02 PM.

  3. #3
    Junior Member
    Join Date
    Dec 2002
    Posts
    12
    Thanks a million. I'll be sure to spend some time on that.
    Just really busy today.

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