dcsimg
A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Swf-Swf communication part 2

  1. #1
    Senior Member
    Join Date
    Nov 2003
    Location
    Los Angeles, California
    Posts
    101

    Swf-Swf communication part 2

    I am able to get data to pass to another .swf file. Problem is, I am only able to send a text string across the connection.

    I need to read in the connection and run a function called arrowForwardOnRelease.

    Here is the code thus far

    Flash File (Sender)
    ======================================
    //assign a function to the button's event method
    userMessage.text = "arrowonrelease"

    buttonInstance.onRelease = function()
    {
    //create the LocalConnection
    outgoing_lc = new LocalConnection();

    //send the contents of the text field
    //using the send() method
    outgoing_lc.send("lc_name", "methodToExecute", userMessage.text);
    };


    Flash File (Reciever)
    ======================================
    //create LocalConnection
    incoming_lc = new LocalConnection();

    //define function to execute when a connection is made
    incoming_lc.methodToExecute = function (param)
    {
    sentMessage.text = param;
    }

    //make the connection
    incoming_lc.connect("lc_name");


    This sends the text over the connection no problem, and the reciever recieves it and outputs it, thing is I need it to then be read in and trigger a function.

    Someone suggested using the eval function to do this, but I am not exactly sure how. Any help is much appreciated.

    Files thus far are attached.

    Thank you

    --J
    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Nov 2003
    Location
    Los Angeles, California
    Posts
    101
    I want to read in the text sent in from the other flash movie, and then have it call a function called arrowonrelease. here are the 2 examples I tried which did not work.

    set ("param", "arrowonrelease");
    if (param="arrowonrelease)
    {
    arrowonrelease()
    }

    Any help is much appreciated.

    Thanks,

    --Jon

  3. #3
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    What is the function supposed to do that your trying to call? Are you trying to use the local connection method to load movies into your reciever movie from the sender movie?

  4. #4
    Senior Member
    Join Date
    Nov 2003
    Location
    Los Angeles, California
    Posts
    101
    I have everything working now and the function being called, but I am currently having issues getting my second button to call my function. It has something to do with the Data I am sending.

    Here is my code.

    Sender.swf
    ================================
    forward.text = "arrowForwardOnRelease"
    back.text = "arrowBackOnRelease"

    nextbtn.onRelease = function()
    {
    new LocalConnection().send("forward", "arrowForwardOnRelease", forward.text);
    };

    backbtn.onRelease = function()
    {
    new LocalConnection().send("backward", "arrowForwardOnRelease", back.text);
    };

    Reciever.swf
    ======================================
    lc = new LocalConnection();
    //=====================================
    lc.arrowForwardOnRelease = function (param) {
    //getURL("javascript:setIdProperty('news_background' , 'backgroundImage', '"+bg+"');");
    if (controlSet<maxSet) {
    controlSet += 1;
    } else if (controlSet>=maxSet) {
    controlSet = 1;
    }
    for (i=0; i<=element_count; i++) {
    if (_root["cell"+i].thisSet == controlSet) {
    _root["cell"+i]._visible = true;
    } else {
    _root["cell"+i]._visible = false;
    }
    }
    }

    lc.arrowForwardOnRelease = function (param) {
    if (controlSet>=2) {
    controlSet -= 1;
    } else if (coltrolSet<=1) {
    controlSet = maxSet-0;
    }
    for (i=0; i<=element_count; i++) {
    if (_root["cell"+i].thisSet == controlSet) {
    _root["cell"+i]._visible = true;
    } else {
    _root["cell"+i]._visible = false;
    }
    }
    };

    //Below this line isnt being called
    lc.arrowBackOnRelease = function (param) {
    if (controlSet>=2) {
    controlSet -= 1;
    } else if (coltrolSet<=1) {
    controlSet = maxSet-0;
    }
    for (i=0; i<=element_count; i++) {
    if (_root["cell"+i].thisSet == controlSet) {
    _root["cell"+i]._visible = true;
    } else {
    _root["cell"+i]._visible = false;
    }
    }
    };
    //make the connection
    lc.connect("forward");
    lc.connect("backward");


    I need for when backbtn.onRelease = function() is pressed that it call on the function in the reciever clip, just like the forward one does. I thought copying and pasting would work, but it hasnt as of yet. Help is much appreciated.

    Thank you

    --Jon

  5. #5
    Senior Member
    Join Date
    Nov 2003
    Location
    Los Angeles, California
    Posts
    101
    Heres the deal. . . . I cant get both valued to be passed in.

    I can only get one to be passed either forward or backward.

    So the line
    lc.connect("forward","backward");

    Will only call the first instance which is Forward. It will not call Backward.

    And if I do the opposite and put backward first then it does not call forward. . . Craziness. . .

    Help please if you have an idea of what is up with this.

    Thanks,

    --Jon

  6. #6
    Senior Member
    Join Date
    Nov 2003
    Location
    Los Angeles, California
    Posts
    101
    Please Help. . .

    Zip file attached.
    Attached Files Attached Files

  7. #7
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    I am still not clear on exactly what your trying to do. I only have Flash MX so I can't look at your demo file. It sounds as though your trying to have buttons in the receiver movie advance the main timeline or a movieclip timeline forward or backward one frame with each press or does each press load a seperate .swf movie? Since I am not exactly sure what your trying to achieve, I made a quick demo that uses the loadMovie command from a button in the sender movie to load a movie into the receiver movie. I set it up like this...

    Sender Movie...
    code:

    sender = new LocalConnection();
    myButton.onRelease = function() {
    myLoad = 0;
    _root.sender.send("ldMovieConnection", "onReceive", myLoad);
    }
    myButton2.onRelease = function() {
    myLoad = 1;
    _root.sender.send("ldMovieConnection", "onReceive", myLoad);
    }



    Receiver Movie...
    code:

    list = ["sun.swf", "spinClip.swf"];
    _root.createEmptyMovieClip("movieHolder",1);
    receiver = new LocalConnection();
    receiver.onReceive = function(myLoad) {
    _root.movieHolder.loadMovie(list[myLoad], 1);
    }
    receiver.connect("ldMovieConnection");



    One other thing, using (as),(/as) or (code),(/code) tags(with brackets instead of parens)when posting code samples makes reading the code samples on these forums much easier.

    The demo file needs to be extracted from the zip file to a regular folder for it to work.

    Hope it helps
    NTD
    Last edited by NTD; 03-16-2005 at 08:08 AM.

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