I can see vars in a textbox, but my script does not work?
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 30

Thread: I can see vars in a textbox, but my script does not work?

  1. #1
    Moderator
    Join Date
    Feb 2001
    Posts
    13,044

    I can see vars in a textbox, but my script does not work?

    Hi,

    this is a very common problem..
    Loadvariables just sends a request to the server, and the movie continues to play. After some time (say a few seconds), flash will have received a response from the server.
    If you are staring at one of those text fields, you just ... wait a moment
    If you want to use the data in your script, you have to add some waiting to your script.
    technique a - frame loop:
    1st frame in row:
    set _some variable you expect_ to a value that will not be sent (if you are expecting a "status" with possible values "ok" or "fail", set it to "waiting")
    loadvariables
    play (in case the movie was stopped and this is a button action)
    2nd frame - no code
    3rd frame:
    if the particular variable still has the _impossible_ value, go back one frame
    4th frame - data is ready for use

    If your data does not contain a suitable variable for the checking, just add one.
    Possible extension: use getTimer when sending to the request and in frame 3 to detect a possible timeout (server does not respond, sends a scrit error instead of data, ...)
    Frames 2 and 3 can be used to show a "server busy" animation

    technique b - event handler:
    if you use a data movieclip (loadvars object), you can use the onclipevent(data) or the onload function. In that case code using the variables would be placed in the event function, or the event function would advance a stopped movie to the next frame

    Musicman

  2. #2
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    Keep it up, MusicMan. I love these FAQ stickies. The last sticky you posted titled "PHP Not Working?" was awesome too.

    Furry
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

  3. #3
    Junior Member
    Join Date
    Dec 2002
    Location
    no were
    Posts
    12

    keep it real man:mrt:

    great sticky !!!

    10x

  4. #4
    Member
    Join Date
    Jan 2003
    Location
    nyc
    Posts
    46
    great post!

    another quick note:
    a good coder will use technique a and b

    also don't forget you need to echo into the object & embed tags if you are trying to pass flash data as it loads up the page

  5. #5

    Problems

    Ok here we go ... It's 3:38 after midnight and I still cand find a solution..

    I have a flashmovie that asks for a username and a password, then it sends them to a php script which conects to a database, checks for the username and password provided and if it finds them it returns a You made it message and a variable called user_check with the value "ok".

    Now the thing is that when I check into the flash movie the variable user_check, it seems like it does not has the OK value in it.

    Yes the testing textbox that I created displays the OK value just fine and yes I have places a delay mechanism with a loop that says
    If user_check == "ok" goto and play the frame that shows a menu else if user_check =="no" goto the beggining of the movie so the user can enter again a username and password, BUT the IF condition in flash acts like the user_check variable is empty or with a different value than the OK value that php script sends.

    The php script works fine and it has no bugs as far as I have seen so I believe the problem has something to do with flash.


    PHP code is here:

    <?
    $dbcnx = mysql_connect("mylocalhost","myusername","mypasswo rd");
    mysql_select_db("access_list",$dbcnx);
    $result=mysql_query("SELECT LoginName, LoginPassword FROM users");
    $authorized="no";
    $username=$_GET['username'];
    $password=$_GET['password'];
    while ($row = mysql_fetch_array($result)){
    if ($username==$row["LoginName"] and $password== $row["LoginPassword"]) {
    print('&_level0.check_status=You Made it');
    print('&_level0.user_check=ok');
    $authorized="yes";
    }
    }
    If ($authorized=="no"){
    print('&_level0.check_status=Authorization Failed');
    print('&_level0.user_check=no');
    }
    ?>

    Actionscript IF command is here:

    if (_level0.user_check=="ok") {
    gotoAndStop(45);
    }

    Do I have something wrong that I cannot find ?

    Please give me a hand or I'll shoot my self
    Lightform - Evolution One

    http://lightform.onar.gr

    Ex - Reactor 5.0

  6. #6
    Moderator
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    a) important security hint: passing username and password via GET method might mean that some systems will reveal the secret data when scrolling through the browser history - use POST method
    b) database hint: do not read all the users...
    select from users where LoginName = '$username' AND LoginPassword = '$password'
    c) try to arrange the movie like that:
    (frame label "form"): movie stopped, form with submit button on stage, button code
    user_check = ""
    loadVariables("login.php", ..., "POST")
    play()
    next frame (framelabel "loop") - no actions
    next frame:
    if(user_check == "") gotoAndPlay("loop")
    else if(user_check == "ok") gotoAndPlay("success")
    else gotoAndPlay("form")

    Musicman

  7. #7
    Xmm the problem persists !

    here's the new PHP code

    <?
    $username=$_POST['username'];
    $password=$_POST['password'];
    $dbcnx = mysql_connect("myhost","myusername","mypassword");
    mysql_select_db("access_list",$dbcnx);
    $ask=('SELECT LoginName, LoginPassword FROM users WHERE LoginName="'.$username.'" AND LoginPassword="'.$password.'"');
    $result=mysql_query($ask,$dbcnx);
    $row=mysql_fetch_array($result);
    if ($row['LoginName']==$username AND $row['LoginPassword']==$password) {
    print('&_level0.check_status=Success');
    print('&_level0.user_check=ok');
    } else {
    print('&_level0.check_status=Failure');
    }
    ?>

    Scripts works ok no problem here

    What happens is again that flash seems to Ignore that user_check variable has a value of ok. Instead it thinks that it is still empty and it goes into an infinite loop!

    Actionscript for checking is here :

    if (user_check=="") {
    gotoAndPlay(44);
    } else if (user_check=="ok") {
    gotoAndStop(45);
    } else {
    gotoAndStop(1);
    }

    44 frame: the one that that returns the timeline to 43 keyframe that contains this checking code

    45 frame: the frame where menu appears is login is correct.

    1 frame: stop action and where the form appears.

    I hate being kind of pain in the ass here but i have spent about 4 hours again with no result.

    Any ideas guys ?
    thank you for your time
    Lightform - Evolution One

    http://lightform.onar.gr

    Ex - Reactor 5.0

  8. #8
    Senior Member
    Join Date
    Mar 2003
    Location
    Maryland
    Posts
    378
    I'm not very good with PHP yet, BUt I don't advice you to have your php script to DIRECTLY connect with the SQL database, open a HUGE ASS security hole. Just letting you know

  9. #9
    Child Prodigy Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    551
    So we shouldn't use mysql_connect? How would you recommend we connect to the database?

    Thankyou,
    Rick
    Code:
      hobby = webDesign; waitYears(3);
      job = webDesign; this.love(job);

  10. #10
    Moderator
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    not sure what kasracer was talking about....

    There is one thing to avoid: never build an app that gets the mysql password and / or complete select commands from the browser unless you are very sure it is protected enough

    Musicman

  11. #11
    Special Member Tea_J's Avatar
    Join Date
    Dec 2000
    Posts
    991
    hmm... looking at all these stuffs ya got, i think it should really work..

    so im guessing, the problem is in your loadVariables command..

    are you sure you got your target set to "this"

    loadVariables("myScript.php",this,"POST")


    other than that, i dont know why it aint working..

  12. #12
    Member
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    47
    Originally posted by kasracer
    I'm not very good with PHP yet, BUt I don't advice you to have your php script to DIRECTLY connect with the SQL database, open a HUGE ASS security hole. Just letting you know
    why is there a security hole ? I always connect directly to my database using :
    Code:
    <?
    $mysqlhost="serverhost";
    $mysqldb="database";
    $mysqluser="username";
    $mysqlpwd="password";
    
    $conn = mysql_connect($mysqlhost, $mysqluser, $mysqlpwd) or die(mysql_error()); 
    mysql_select_db($mysqldb, $conn) or die(mysql_error());
    ?>
    Every PHP&MySQL tutorial will teach you the same thing...

    PS: to the starter of this thread : Is your .swf file on the same server as the php script(s) you're running ? otherwise Flash&PHP won't be able to communicate.

    greetz, ava
    --== A Flash N00B ==--
    http://www.avaweb.be

  13. #13
    Member
    Join Date
    Dec 2001
    Posts
    32

    usrname &psswrd

    A good coding practice is to put your database username and password in a separate file outside your public_html directory and use include(''); to make this data available to your PHP script. This is done to prevent an HTTP user from viewing the file if they create conditions under which your script won't execute and will get displayed as simple text revealing all the sensitive data.

  14. #14
    Junior Member
    Join Date
    Aug 2003
    Posts
    8
    Anothing thing is to create separate accounts for different actions. For all PHP pages that access the database from a remote host the user I created only has the select command. Any user that has higher privileges has to be localhost only.

  15. #15
    FLESRUOYLLIK
    Join Date
    Jul 2000
    Location
    Behind you…
    Posts
    118

    please help

    Hi,
    I've set up a simple username/password section in my site using one of the tutorials from this site, it works fine but all the usernames / passwords are internal in my Flash movie and therefore when I add new ones I will have to republish the site, is there any way of geting it to read a simple external text file that would contain all of my username/passwords? I also found a tutorial on getting flash to load text into a movie from an external file so really I'm just trying to combine the two…
    Would somebody be able to direct me to an appropriate tutorial or .fla? I don't want to use PHP or other language.
    Any help would be appreciated,
    Cheers Wayne
    www.lushnewmedia.com
    . . . . . . . . . . . . . . . . . . . . .

  16. #16
    Junior Member
    Join Date
    Aug 2003
    Posts
    8
    mmm well yes you can read in a text file. Check out the tutorials that came with flash it should have a walkthrough on how to do it. The only problem is that when you use a text document it wouldn't be secure unless you have them encrypted and then write some encryption into your flash program. I think you have to setup the text file like

    [Loadvars]
    Blah="hey"

    Not 100% since I've moved to a PHP based system.

  17. #17
    Ihoss
    Guest
    thought id just add some stuff to this:

    if ur on a free server chances r that there will be ads on the page, so u need something like this in the php:
    PHP Code:
    print("?name=$name&id=$id&waste="); 
    when u view a normal web site the ad code is after the rest of the code. so is it if u use loadVars. but if u didnt have the &waste= part that code would be part of the id variable. now it is part of the waste variable. then in your flash u can say that waste =1; and all of the ad code is gone.

    there is a problem with this mehtod and that is that the ad code will sometimes contain & or something and then a new variable is created. if anyone know of a better way, please share it.

  18. #18
    Junior Member
    Join Date
    Mar 2002
    Location
    Portugal
    Posts
    5

    Text files and passwords

    To Electrolux,

    Reading a .txt file in Flash is really simple but not suitable for passwords.
    Just put a .txt file on your server and type the address in a browser. Yep! Everyone can read all your names and passwords in a beautifull Courier font type.

    So there goes the basic idea of usernames and passwords: security.

    Conclusion: Flash alone is not suitable for passwords.

    And IggyV doesn't help either: the passwords
    in your .swf are relatively save (if the fla is published with the "protect from import".) Creating an .as (= text file!) is readable for everybody.

    The only way to use pretty safe ways of the name and password stuff: a serverside scripting and/or a database. (PHP, CGI, MySQL and if you really want trouble: (MicroSoft) ASP).

    Sorry, but you have to dig deeper into coding.

    Greetz,
    Sckz
    [ A camel is a horse, designed by a comittee ]

  19. #19
    Moderator
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    protect from import does not really imrove the security of text inside a swf

    Musicman

  20. #20
    Learn more, know less.
    Join Date
    Jul 2004
    Posts
    169

    You guys know stuff, please help.

    Hey guys,

    I kind of feel like an ass for posting a simple question in the middle of your database conversation, but I need somebody who knows flash and PHP to pinpoint my issue.

    I have attached the .fla (which is loaded into my _root swf) and a txt file with my PHP script, which is based on Musicman's tutorial on emailing with PHP. I am working with PHP 4.3.5, but I have tried to use all the updated scripting that Musicman suggested.

    I have obviously missed/don't understand something, because the swf will do what it's supposed to, and the script seems fine, but they don't connect to each other.

    Please help and offer an explanation if you can...I really want to understand this stuff, but I'm a lot less knowledgable in PHP than with Flash.

    Thanks.
    Attached Files Attached Files

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

Poll by Flashkit.com