dcsimg
A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Loading dynamic, real-time data without a refresh... need help

  1. #1
    Junior Member
    Join Date
    May 2002
    Posts
    8
    I am working on a flash applet that displays several variables from two separate variable files, each is reloaded every 2 frames, on a local system setup, if i save the variables file with a different one that is currently displayed in the running flash display, it updates itself automatically, on a web interface (the files over a net connection) it doesn't do that (saving the variables file to the web server doesn't update the data) i need a way to update variables without having to refresh/reload the page.

    Any thoughts?

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    CGI

    Hi,

    If you are using static text files to display the data, you can't prevent caching of the data.

    The best way around this is to send the loadVariables command to a cgi script, with a random variable (that tricks your browser into thinking it's a different url).

    The cgi script would then open the text file, read and format the variables, and post them back to your flash movie.

    An example would be using getTimer() such as:

    Code:
    loadVariables("http://yoursite.com/yourscript.php?dummyVar=" add getTimer(),"");
    Hope this helps,

    Dan.

  3. #3
    Junior Member
    Join Date
    May 2002
    Posts
    8
    ok...
    I have zero experience with php, is this just a dummy php script, or is there work involved?
    the file names in question (variable data files) evdata.txt and regflash.txt i can add in the complete url myself, just need some help putting this together.

  4. #4
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    PHP

    Hi,

    The script doesn't have to be PHP, it could be PERL, ASP, Cold Fusion, whatever your comfortable with.

    The script isn't a dummy script, It needs to open up your text file, read in the data, and send it to the flash movie.

    However saying that, (and this may be my lack of understanding your project) If your data sits in a text file, I don't imagine you are dynamically creating the contents with a server side app, so why is there an issue with caching, and why update the vars every 2 frames if the data hasn't changed?

    Dan.

  5. #5
    Junior Member
    Join Date
    May 2002
    Posts
    8
    The regflash.txt file (the only one that needs to be updated dynamically) is an output of a separate PHP script, so it is updated at unregular intervals, and the data should change in the flash movie when the data in this output file also changes. using a straight txt file is the easiest in my situation. PHP is best, as the rest of the site is being developed in this, if it's not to much troubler, could such a script be written easily?
    thanks.
    BN

  6. #6
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    Very easily

    Hello again,

    Yep, very easy to write.

    I presume that you are writing the text file within php using the urlencode($yourstring) method, to ensure that flash recieves the vars correctly. (if you're not, you should be!).

    In which case, all you need to do in the script you call from flash is open the file, read the data into a variable and print or echo it!

    I suggest you read up on the PHP filesystem methods here:

    http://www.phpbuilder.com/manual/ref.filesystem.php

    Don't worry, it's really easy, here's an example:

    Code:
    $file = "\your_server\your_dir\regflash.txt";
    
    $read_file = @fopen($file, "r");
    
    $contents = fread($read_file, filesize($file));
    
    fclose($file);
    
    print $contents;
    A synch eh???

    Dan.


  7. #7
    Junior Member
    Join Date
    May 2002
    Posts
    8
    Cool!
    I hope it works, the output file already formats the data in format flash can read ex:
    Code:
    "&count=17"
    so i hope that thats exactly what's needed, i just make a php script, set up proper permissions (read, write and execute i presume) and away i go, eh?

    thanx
    [Edited by Collective_8472 on 05-17-2002 at 12:36 PM]

  8. #8
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    That's it!

    Yep,

    You've got it.

    The script is only there because you can't append anything to the end of the path to your textfile (to trick your browser into thinking it hasn't read it before), so you append the random var, or timer var to the script path, which literally gets the file and posts it's contents back to you.






  9. #9
    Junior Member
    Join Date
    May 2002
    Posts
    8
    ok, wrote the script, uploaded in ascii, chmod 777. now, i can't get the thing to read the file, they are in the same directory so the entry in the $file string is just "regflash.txt" is that a bad thing or should this be an absolute, i re-wrote it as an absolute and am trying again, any help...

    Ammend:

    It's not working, is there anything i need to do to the loadvariables action, the script's path tom the file or the dynamic text boxes (thay are set with the vars "regcount" and "names" same as in the regflash.txt file.
    they don't show up, whats up with that.

    BN

  10. #10
    Senior Member
    Join Date
    Jul 2000
    Posts
    266
    Hi,

    You don't even need chmod PHP like you do with PERL.

    Can't tell you without seeing:

    1. php file,

    2. text file,

    3. code that loads the vars.

    Post them, or a link, or mail to me: dan@technomedia.co.uk

    and I'll take a look for you.

    Dan.

  11. #11
    Junior Member
    Join Date
    May 2002
    Posts
    8
    the fla file:
    http://sol.slagg.org/new/eventstatus.fla
    the regcount box is on the right side, the first of two square dynamic boxes (to the left of the "of") and the "names" variable is a dynamic box in the movie clip directly below it (the white bordered box) the setup may be confusing, but i'm not very organized, if you can also help with the scrolling of the names variable that'd be a help too, the vars files are:
    http://sol.slagg.org/new/regflash.txt
    http://sol.slagg.org/new/evdata.txt
    the php script:
    http://sol.slagg.org/new/readscript.php

    email me the changed files to: newton@saraquest.net
    thanx.

  12. #12
    Senior Member
    Join Date
    Jul 2000
    Posts
    266
    Hi,

    I didn't mean to simply copy the code I posted exactly and that was your script - it's just a snippet.

    You need to enclose the script in php tags <? and ?> and you need to use the absolute server path to your script ie:

    /home/www/website/directory/regflash.txt

    Also, the php script that is writing your file of names needs some work to format the output a little better - it isn't properly url encoded - your names are loaded into flash like this:

    "Snazz\r\nBig-Mamma-=KCG=-\r\nCollective_8472\r\nCyclops\r\nDrFoo\r\nGman\r\ nMrBigglesworth\r\nMREBoy\r\nNinja_Midget\r\npYr0m 4ni4Ck\r\nSpike\r\nSpitfire\r\nTerroSeal-=KCG=-\r\nTwitch\r\nviKaNe\r\nWizard\r\n\r\n\r\n\r\n"

    Pretty difficult to work with eh?

    I don't mind helping, however I'm not doing all the work or you won't learn. (I'm not being funny!)

    Try what I've suggested, let me know how you get on, and we'll take it from there.

    Dan.

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