A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: percentage wont show in external txt file

  1. #1
    Senior Member
    Join Date
    Mar 2007
    Posts
    107

    percentage wont show in external txt file

    Hello i have been trying to figure out why wont flash display the following characters from my external txt file... % + Percentage and plus are out...as if they dont exist...they are in the txt file...but they dont display in the flash file.....

    heres the code

    var myData = new LoadVars();
    myData.onLoad = function() {
    myText_txt.text = this.content;
    };
    myData.load("price.txt");


    could the problem be in te actionscript? or is it a flash problem generally....

    Thanks a lot for your time

  2. #2
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    This looks like AS2 to me, which means you need to either code in AS3 or switch to the other forum. =)

    % and + are both used syntactically in URLVariables. + is often used as a separator, and % is an escape character for special characters (for example, a space becomes %20 in URLVariables). It's possible that because you are using LoadVars, it's trying to interpret variables. I bet & also gives you troubles.

  3. #3
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    ...

  4. #4
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Right. Add backslashes to the text file before sending it this way. Better yet, write the following bit of php code and call it instead:

    Code:
    //name this code loadfile.php
    //call it using loadfile.php?f=filename
    <?php
       $h=fopen($_GET["f"]);
       $content = addslashes(fread($h,filesize($h)));
       echo $content;
    ?>

  5. #5
    Senior Member
    Join Date
    Mar 2007
    Posts
    107
    Right ...thanks for your answers... i quess i will have to switch to that php code which i have no idea how to add that

    Johnstrike... how do i add that code? Do i have to create a php file with that code in it? Or does that code goes in my flash movie...

    Thanks a lot for trying to help me out!

  6. #6
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    Add it to a text file called loadfile.php. (See the two lines of comments at the top that tell you how to use it?)

  7. #7
    Senior Member
    Join Date
    Mar 2007
    Posts
    107
    Hello...i dont know what i am doing wrong but it doesnt work

    I have my price.txt with this information in it...

    content=
    Everything today is 70% off!!!


    I have my loadfile.php text file with this info in it...

    <?php
    $h=fopen($_GET["f"]);
    $content = addslashes(fread($h,filesize($h)));
    echo $content;
    ?>


    and the flash file with the following code,...

    var myData = new LoadVars();
    myData.onLoad = function() {
    myText_txt.text = this.content;
    };
    myData.load("price.txt");


    What am i doing wrong?
    How can flash get the php code?

  8. #8
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    myData.load("loadfile.php?f=price.txt");

    BTW, this will only work if you post it to a webserver with PHP turned on. Flash doesn't interpret PHP.

  9. #9
    Senior Member
    Join Date
    Mar 2007
    Posts
    107
    ok...i get the logic behind the code ...but still it wont work...i tested it in a server supporting php but still nothing./..

    Should it work if i just test it locally on my computer? do i have to upload it live on the net to test this?

  10. #10
    Member
    Join Date
    Apr 2003
    Location
    North East, MD
    Posts
    62
    The only way you can run this is using the php method is to either 1) have php running locally, or 2) put the output of the php script in a local text file and just try reading that in.

    After all, php just spits out text (for the most part). So you can simulate it by #2 above
    "I hate when people put quotes in their signatures" -anonymous

  11. #11
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    You need to have the PHP code running on the same server where the SWF is located otherwise you'll have sandbox issues unless you add a line to the top of your flash code like:

    Security.allowDomain('domain.com'); to whatever domain the PHP code is running, then you can test it locally against a remote PHP server.

    I don't know if you're creating a back-end for this thing and that's why you need it to import text files on the fly, but if you're in any way letting people input data on a back-end into text files that you're then getting flash to read, you ought to consider adding slashes to the text at the point of entry, so the text file is already correct. Otherwise you may run into the same problem with people entering "70%" as you have getting it out of the file...

  12. #12
    Senior Member
    Join Date
    Mar 2007
    Posts
    107
    hello again thanks for helping me out on this...

    Basicly what this is...is a project about a store that has big plasma Tvs in it where they are connected to a computer inside the store. That computer is connected to a server where it plays a series of flash animations , both interactive and not. This project doesnt belong in a website or anything....it just plays on the plasma TV through that computer. The user just changes the txt file and it appears on the big screen...

    so i quess i have to go with using the slashes in my txt file?

    can you give me an example of that? cause i already tried everything and im a bit lost here

  13. #13
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    put a backslash in before your % and see if it helps. if not, look up the html encoding values. %25 is the % sign.

  14. #14
    Senior Member
    Join Date
    Mar 2007
    Posts
    107
    nope...still nothing .. maybe this doenst work... thanks for all your help..

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