A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Download counter? Help plz!

  1. #1
    Member
    Join Date
    Mar 2011
    Posts
    68

    Question Download counter? Help plz!

    hey guys,

    how do i make a normal download counter for some pieces of software and artwork that i have in my website? do i have to store the hits on a xml list?

    Thanks:

    Duarte V.

  2. #2
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    XML, database or text file, and you need some server side language as well.
    [SIGPIC][/SIGPIC]

  3. #3
    Member
    Join Date
    Mar 2011
    Posts
    68
    thanks, but what is server side language? :s

  4. #4
    Member
    Join Date
    Mar 2011
    Posts
    68
    ok sorry, im not used to english terms about this questions :s i checked it out... DreamWeaver CS5 is ok? right?, i just need to insert the swf there with the download button linked to a text file wich may be enough for me from the chances you gave above... and is all cool right? ... if so i just need to check some things in internet to know how to write and read directly from a text file wich i think is not very hard...at least i hope Thanks Again

  5. #5
    Dignitary rynoe's Avatar
    Join Date
    Jan 2003
    Location
    Earth
    Posts
    760
    Server side language is installed on your server. Examples are PHP, ASP and perl. Dreamweaver will only create a webpage.
    Last edited by rynoe; 04-02-2013 at 06:35 PM.
    [SIGPIC][/SIGPIC]

  6. #6
    Member
    Join Date
    Mar 2011
    Posts
    68
    cant i read/write from/to a text file in the server through embed swf on a html?

  7. #7
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    You need a database setup MySQL and store your information into a table of that database. Obviously you need PHP or any other Server Side Language which will communicate from your frontend Client Side Apps. This will help you to store everything you need to store and also get counting how many success download you have.

    The thing is that by applying this process you can have a control on both members area download ans the public area if you have any free download section.

    enjoy

    arkitx

  8. #8
    Member
    Join Date
    Mar 2011
    Posts
    68

    Question

    Thanks, i´ve downloaded a fla with the php code from here cause i dont know how to draw one, anyway i could not set the code to work, it was somehow based on the html page and not on the flash download button...to be more specific it was a hit counter for visitors and not a download counter, i just could not integrate the code in my download button... the base code on the fla was the following:

    Code:
     onClipEvent(data){
    with(_root){
    this.hitno = hitno;
    gotoAndPlay(4);
    }
    }
    i just load the movie and it does not made alterations on the hit.txt file, well i know this was meant to a direct movieClip and not to a button... i just do not know how to update it into the button, and i tried in my html, and the same thing...

    any idea???!!! .... im very basic on this, specialy with php cause ive never used it before???!!!!!!

  9. #9
    Senior Member
    Join Date
    Jan 2011
    Posts
    171
    @Alienoiz: Well you can do by read/write a .txt file from the server. Flash can directly read .txt file from anywhere but cann't write into it. To write into the .txt file Flash has to call a .php file from the server and that .php will do the job to write a counter number on every download hit made from Flash (.swf).

    PHP is a free Server Side Language and it is quite easy to learn the basic of it.
    You can get lots of tutorials on Flash PHP communication.
    To write into a .txt file through PHP, you need the following php inbuild function to achive:

    fopen();
    fread();
    fwrite();
    fclose();

    You can read and get the wholde bunch of codes from www.php.net or you can get tutorials on this subject from net.

    If you still not able to find your solution, please come back and let us know how far you achived. We will sure you will get it soon....

    Bet Wishes


    arkitx

  10. #10
    Member
    Join Date
    Mar 2011
    Posts
    68
    ok guys, i made some research and ive gone into this...

    i now can read from a .txt file but still cannot write on it :s ...... this is the code i got so far:

    PHP:

    Code:
    <?php
    $mytxt =$_POST['hsdata'];
    $myfile = "text.txt";
    $fh = fopen($myfile,'w');
    fwrite($fh, $mytxt);
    fclose ($fh);
    ?>
    Flash:

    TimeLine - First Frame:

    Code:
    loadText = new LoadVars();
    loadText.onData = function(raw) { Field2.text = raw };
    loadText.load("text.txt");
    Button1 :

    Code:
    on (click) {
     var outLV = new LoadVars();
     var inLV = new LoadVars();
    function sendData() {
    outLV.hsdata = Field1.text;
    outLV.sendAndLoad("host.php",inLV,"POST");
    }
    }
    may you tell me what is wrong here?
    I didnt tried to use it on an html path...
    is it needed to be on http:// path or c:\ is enough?
    Thanks:

    Duarte V.

  11. #11
    Member
    Join Date
    Mar 2011
    Posts
    68
    ok..i have tested it on the server, first of all it asks me for a password and username to access the test folder where is the content???!!!! i dont know how overpass this for common users, then it still does not work...it just does not writes on the .txt file ((((

  12. #12
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Lets see if we can help you,

    the button on (click) will not work, its on (press), but try this,
    all on the time line. with your button called myButton, remove the code placed on your button
    PHP Code:
    // *** Get initial value
    loadText = new LoadVars();
    loadText.onData = function(ok)
    {
        if (
    ok)
        {
            
    Field2.text ok;
        }
    };
    loadText.load("text.txt");
    // *** Button press
    myButton.onPress = function()
    {
        
    SubmitData();
    };
    // *** Send Data
    function SubmitData()
    {
        
    trace("Sent");
        var 
    outLV = new LoadVars();
        
    outLV.hsdata Field1.text;
        var 
    inLV = new LoadVars();
        
    inLV.onData DataReturned;
        
    outLV.sendAndLoad("host.php",inLV,"POST");
    }
    // *** Received data
    function DataReturned(ok)
    {
        if (
    ok)
        {
            
    trace("Received");
            
    Field2.text ok;
        }

    for the corresponding php file use this
    PHP Code:
    <?php

    $mytxt 
    $_POST['hsdata'];
    $myfile "text.txt";

    $fh fopen($myfile,'w');
    fwrite($fh$mytxt);
    fclose($fh);

    echo 
    $mytxt;

    ?>
    this is basic, and I think you want to add up numbers for your counter, but get this working first then we can do the counting after.

    for that you need to read the file first, then add 1 to the number, write it, close it then display it.

    I'm not so sure why your are being asked for password, i use apache, wamp ect and dont get asked for password unless i make it ask for one.

  13. #13
    Member
    Join Date
    Mar 2011
    Posts
    68
    hey fruitbeard, thanks for replying.... but im having 2 probs here that i cannot understand... the txt file is not written and the fla returns into Field2 the data that is on the php file when i press the button, and not the data that is on the txt file for default???!!!!!

  14. #14
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Read directly from .txt

    Write via PHP and get return the successful message after writing.


    poltuda

  15. #15
    Member
    Join Date
    Mar 2011
    Posts
    68
    hey guys ...leave it.. im to dumb to know how to write on my txt file through php ... im just not able to write on the txt file. the fruibeard´s piece of code says is all good, sent and received ok, but in my txt file theres no kind of new text there and it just returns into my Field2 what is written on the php and not what is on the txt... i see that is very easy to read from a txt but it seems to hard for me to figure out how we write on it.. Thanks!

    Duarte V.

  16. #16
    Member
    Join Date
    Mar 2011
    Posts
    68
    here it is all my doubt.. ive been looking to this simple code and i keep asking myself what is needed here:

    this function:
    Code:
    function SubmitData()
    {
        trace("Sent");
        var outLV = new LoadVars();
        outLV.hsdata = Field1.text;
        var inLV = new LoadVars();
        inLV.onData = DataReturned;
        outLV.sendAndLoad("host.php",inLV,"POST");
    }
    should send into the php file the data of the text Field1 that it will write on the txt file after pressing the button.. ..i mean... when i press the button it grabs the data from the Filed1, send it to the php script and then the php script writes it on the txt file...right???

    well i dont know how does the txt file is not written???

    this is my first problem...im assuming that if this is solve i might have another by increasing the number into the next one each time the button is clicked ?! :s

Tags for this Thread

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