dcsimg
A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: LoadVariables from PHP to my MC

  1. #1
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Okay guys, I got a big headache here. I'm trying to load variables into my MC from php. It works fine if I'm doing it from the scene, but put it into an MC, and it doesn't work at all. I've tried EVERY possible thing there is that I can think of, and also all the info I found through all the forums, but nothing's worked yet. I know that it's nothing to do with the PHP, because it works perfectly from the movie, just not the MC.
    Let's pretend that my MC is named newmsgs2, my MC instance is also named newmsgs2, and my textbox variable on the first frame of my MC is called newmsgs. Please please please help me out.

    Riki

  2. #2
    Moderator
    Join Date
    Aug 2000
    Posts
    1,455
    Hiya!

    I'm not sure where you're calling loadVariables from but the test movie that I set up works just fine.

    Within the newmsgs2 MC I simply had a button with the followin AS:

    Code:
    on (release) {
        loadVariables("newmsgs.php", this);
    }
    And the contents of the newmsgs.php file was simply:

    Code:
    <?php
    
    echo "&newmsgs=" . urlencode("This is some nice and tasty dynamically loaded text.") . "&";
    
    ?>
    I also placed a button outside the MC on the _root level with the following AS:

    Code:
    on (release) {
        loadVariables("newmsgs2.php", _root.newmsgs2);
    }
    With newmsgs2.php being:

    Code:
    <?php
    
    echo "&newmsgs=" . urlencode("This is another dynamically loaded message") . "&";
    
    ?>

    If this doesn't help solve your problem then let me know and I'll see what I can do!

    Regards,

    Steve

  3. #3
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Hey, okay, well, I only work on the flash part, my friend is working on the php stuff. It's 3 am right now, plus he's out of town for another two days, but I'll let you know how it works out. Do you think you can give me the .fla? or even the whole thing with the php? You can send it to rtanone@hotmail.com if you're willing. If not, that's okay too, coz you've helped a lot anyways If I'm still running into problems, I'll post a reply here. Thanks.

    Riki

  4. #4
    Originally posted by Grifter730
    Do you think you can give me the .fla? or even the whole thing with the php?
    If you haven't gotten an example file, let me know and I'll email you an fla. I have a similar example of how this should work from inside flash.

    Until your friend returns, you could double check to make sure that something is being loaded into Flash from the loadVariables action.

    Test the movie from within Flash. Click your button (or whatever you're doing to load the variables) and then choose Debug | List Variables from the menu bar. If you are getting variables passed to the movie, then you should see new values that were not there before you click the button.... are the variable names misspelled in the PHP script? They'll show up in your Flash variables misspelled as well.


  5. #5
    Moderator
    Join Date
    Aug 2000
    Posts
    1,455
    Hiya!

    The email has been sent with everything attached in a zip file.

    Regards,

    Steve

  6. #6
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Thanks to both of you guys so far. I'm at my family's house, and I'll be looking at it tomorrow (Monday). I DID notice one thing that's very odd though. In the example you gave me, you didn't use POST or GET. I don't understand how this can still work?
    Also, I think hotmail is $%@#$ up. I haven't gotten the files yet. My work email is riki.tanone@healthsouth.com. If I haven't gotten the example by tomorrow, please send me a copy there. Thank you so much for everything so far.

    Riki

  7. #7
    You'll ONLY need to use GET or POST if you are sending the values of variables already in your movie to the server.

    If you are just getting variables from a script, you generally don't need to send variables to the server -- so you can leave out the GET or POST.

    An example of when you might need to send variables TO the server might be if you were getting a stock quote for a user. The user could request a quote by putting the ticker (ex. "MCHP") symbol into a field, "ticker". To get the current quote, you would send the value of that variable to the script on the server by using either GET or POST. Using either of these will send ALL of your variables in the current timeline (are you calling loadvariables from root or from a movieclip?). So if you had a "username" and "password" variable in the current timeline, those would automatically be sent as well.

    The script on the server could check the value for "ticker", do a query on a database, and then return a value to your movie, maybe as the variable "current_price".


  8. #8
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Alright guys, I couldn't wait till tomorrow, so I checked it out. So this is what happened. I was getting the correct response from my php. BUT... to understand the problem you have to know what I'm trying to do, so I'll explain.

    I'm making a program, where people can log in. Once they log in, I have the username variable outside of my movie so that the php knows the person that's logged in. Now, when they're checking for 'new messages' the action is from INSIDE a movie clip. So if I have 3 new msgs, the movie clip should say "3", but instead, it's saying "0" all the time because the php is not getting the username variable. It's outside of my _root, but I'm assuming I need one from inside the MC too.

    So, what I need to do, is I need to pass my username variable from INSIDE my movie clip, to my php. Is this even possible?? I can pass the username variable from the _root just fine. I don't even understand WHY php needs to have the same variable inside the MC.

    If there's a way to work around this, please let me know. If not, what do you guys suggest would be the best solution?


  9. #9
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Oh, I think I got it. Can I have a username inside my MC, equal the same thing as the username variable in my _root? What's the actionscript for making a variable inside my mc equal to a variable outside my MC??

    Riki

  10. #10
    Originally posted by Grifter730
    Once they log in, I have the username variable outside of my movie so that the php knows the person that's logged in.
    Do you mean that the username is outside of the movieCLIP? I'm guessing that you mean the username variable is in the _root timeline.

    In any case, as I think I mentioned above, the only variables that will be sent to the server are those that reside within the same timeline where the loadVariables() action is being called. Yes, you will need to use either GET or POST to send the username variable to the server.

    If you are calling the loadVariables action from inside a movie clip, then you'll first need to make a copy of the username variable in the movie clip. From inside the clip, you could simply say:
    Code:
    username = _root.username;
    and then you would do your normal loadVariables action.




  11. #11
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Sorry to keep posting replies, I'm trying to update you guys. I managed you make the variable inside my MC = the username variable outside my MC. But the php still can't get the variable inside the MC Dead end. I guess I gotta figure out another way to make it keep looping and checking for new msgs every 10 secs

  12. #12
    Do you mean that you can't get the variable loaded into the movie from PHP?

    Here's a word of caution -- if you are loading a variable, "messages," from PHP using loadVariables(), you won't have a value for that variable until the server has had time to process the script and send the value back to the movie.

    A good workaround is to setup a sequence of 3 frames for loading the variable.

    In the first frame, empty out any value for the variable you wish to load. Then write your loadVariables action.

    Code:
    username = _root.username;
    messages = null;    // make messages an empty value
    loadVariables("scriptname.php", this, "GET");
    Leave the second frame blank.

    In the third frame, you can loop back to the second frame until the variable has been given a value.

    Code:
    if (messages == null) {
        // messages still hasn't been loaded
        gotoAndPlay(_currentFrame-1);
    } else {
        // do whatever needs to be done
        // once the variable is loaded
    }

    The only thing to watch out for here is that sometimes your script might time out, or not return a proper value for messages (maybe sending a value for mesages (misspelled)). Then you would be stuck in a loop. So you might want to set up a look so that it will only loop for a certain number of seconds before trying to move on.

    Code:
    if (loopIndex < 120 && messages == null) {
        // messages still hasn't been loaded
        gotoAndPlay(_currentFrame-1);
        loopIndex += 1;   // make sure you initialize this somewhere
    
    } else if (messages != null) {
        // do whatever needs to be done
        // once the variable is loaded
        ....
        ....
    
    } else {
        // what should be done if it's been more
        // than 10 seconds (120 frames @ 12fps)
        gotoAndPlay("error");
    
    }

    I just did something similar in a movie that I was working with loading data from a database using PHP. If you want to take a look at the .fla, it's linked on the following site:

    http://www.embimedia.com/madlibs.html


    [Edited by mikebrittain on 05-20-2001 at 09:35 PM]

  13. #13
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    Dude, you freaking own own own!!! The 3 frame loop works like a charm! Man, I'm learning so much stuff If you wanna see the project, give me your email address and I'll mail you guys the URL. Thanks a lot.

    Riki

  14. #14
    "Own"? I must be getting old. I don't understand that. =)

    yes, please send me a copy. I would love to see it.

    mbrittai@cs.du.edu

  15. #15
    Senior Member
    Join Date
    Oct 2000
    Posts
    412
    I just sent you an email. I wasn't sure if you mistyped your email address or not, so I sent a cc copy to mbrittain also just in case.

    Btw, you own = you rule ^_^;

    Riki

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