【问题标题】:Counter in ActionScript 3.0 with...PHP or?ActionScript 3.0 中的计数器... PHP 还是?
【发布时间】:2011-11-21 17:03:34
【问题描述】:

我正在为多个客户制作此 Flash 横幅,其中一个主要要求是设置某种计数器,以便他们知道横幅被点击了多少次。

我知道如何在 ActionScript 3.0 中执行此操作,我制作了一个简单的 var:int 并在单击横幅时将其增加 +1。我如何处理这个 var 的值(比如它的 121)我在哪里在线存储它以便它安全并且可以通过多个 Flash 横幅(as3)进行更改。

但是我如何保存此信息,以便下次加载横幅时(在不同的网页上)点击次数与上次加载时相同。

我应该为此研究 PHP 吗?我不知道如何做到这一点...一些示例,教程,任何可行的...将不胜感激。(我是设计师,而不是程序员...请不要说php-ish,或者您知道... :D)

我在谷歌上搜索了一下,找到了一些帮助,但我仍然感到困惑,其中大部分不是 AS3,我想也许自从我发现的东西(2008 年)以来,东西已经进化了一些。 .

非常感谢。

【问题讨论】:

    标签: php actionscript-3


    【解决方案1】:

    您必须将值存储(并获取)某处 - 在数据库中、在文本文件中、...

    我会去搜索有关 PHP+MySQL 的教程。如果你不喜欢 PHP-ish,你可能最好找到另一个解决方案:p

    示例教程:http://www.freewebmasterhelp.com/tutorials/phpmysql

    【讨论】:

      【解决方案2】:

      您需要将希望从多个客户端检索/更新的数据存储在服务器上。

      您可以在数据库中使用任何服务器端语言。

      服务器语言:PHP、ASP.net、JSP、ColdFusion
      数据库:MySQL、MSSQL、PostgreSQL、Oracle、DB2 等。

      使用任何你喜欢的组合。

      一般来说:

      1. 您有一个 Web 应用程序可以递增数据库中的计数器
      2. 使用来自 AS3 横幅的 URLLoader 调用页面。

      数据库

      counter_table
      -------------
      counter     INT
      

      PHP 文件

      $db = mysql_connect('localhost', 'mysql_user', 'mysql_password');
      mysql_select_db('database_name');
      mysql_query('UPDATE counter_table SET counter = counter + 1');
      

      AS3 横幅

      // url request with your php page address
      var scriptRequest:URLRequest = new URLRequest("http://www.example.com/script.php");
      
      // loader
      var scriptLoader:URLLoader = new URLLoader();
      
      // load page to trigger database update
      scriptLoader.load(scriptRequest);
      

      您是否也想检索 Banner 中的点击次数的值?

      【讨论】:

        【解决方案3】:

        简单的解决方案(真的不是最好的:)您应该使用其他答案之一..无论如何,制作一个读取包含访问次数的txt文件的php文件..并在您的flashbanner中调用php文件。每次调用都会增加一击..

        PHP:

        <?php 
        
        /** 
         * Create an empty text file called counterlog.txt and  
         * upload to the same directory as the page you want to  
         * count hits for. 
         *  
         * 
         * @Flavius Frantz: YOU DONT NEED THESE:
         * Add this line of code on your page: 
         * <?php include "text_file_hit_counter.php"; ?> 
         */ 
        
        // Open the file for reading 
        $fp = fopen("counterlog.txt", "r"); 
        
        // Get the existing count 
        $count = fread($fp, 1024); 
        
        // Close the file 
        fclose($fp); 
        
        // Add 1 to the existing count 
        $count = $count + 1; 
        
        // Display the number of hits 
        // If you don't want to display it, comment out this line 
        //echo "<p>Page views:" . $count . "</p>"; 
        
        // Reopen the file and erase the contents 
        $fp = fopen("counterlog.txt", "w"); 
        
        // Write the new count to the file 
        fwrite($fp, $count); 
        
        // Close the file 
        fclose($fp); 
        
        ?> 
        

        示例代码来自:(google:php 计数器文件)http://www.totallyphp.co.uk/text-file-hit-counter 代码未经测试,但看起来不错。我只评论了一点..

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-03-09
          • 2015-07-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多