免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2016 | 回复: 0
打印 上一主题 下一主题

求助——amfphp的返回数据问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-02-18 09:54 |只看该作者 |倒序浏览
帮朋友改写一个Flash实现的投票。原来的实现方式为Flash remoting+ColdFusion+MSSQL,需要改成Flash remoting+php+MSSQL.找到使用amfphp来实现和flash remoting的通讯。但是数据返回的时候,遇到一个问题:在Flash端,显示不出数据,随后通过amfphp自带的Browser查看,

php代码:

<?php
class GetPollInfo
{
        var $dbhost = "127.0.0.1"; //数据库地址
        var $dbname = "wnwbeauty"; //数据库名称
        var $dbuser = "wnwadmin";  //数据库用户名
        var $dbpass = "123456";   //数据库密码
        var $conn; //数据库连
       
        function get_data(){
                $conn = @mssql_connect($this->dbhost, $this->dbuser, $this->dbpass) or die("Couldn't connect to $myserver";
                $d = @mssql_select_db($this->dbname, $conn) or die("Couldn't open database $this->dbname";
                  $strQuery = "SELECT q.vcPollQuestion as vcPollQuestion, q.intPollQuestionId as intPollQuestionId, a.vcPollAnswer as vcPollAnswer, a.intPollAnswerId as intPollAnswerId ";
                $strQuery.= "FROM tblPollQuestion q, tblPollAnswer a WHERE q.intPollQuestionActive = 1 AND q.intPollQuestionId = a.intPollQuestionId ";
                $strQuery.= "ORDER BY a.intPollSortOrder";
                $result = mssql_query($strQuery);
               
                while ($row = mssql_fetch_object($result)) {
                                                  $ArrayOfUsers[] = $row;
                                }
                                return $result;        
        //return "found";
        }
       
}
        //debug
        //$f = new GetPollInfo;
        //print_r($f->get_data());
?>
如果打开//$f = new GetPollInfo;
        //print_r($f->get_data()); ,直接执行GetPollInfo.php文件,返回结果为Resource #id 3

browser的results显示

(mx.collections::ArrayCollection)#0
  filterFunction = (null)
  length = 4
  list = (mx.collections::ArrayList)#1
    length = 4
    source = (Array)#2
      [0] (Object)#3
      [1] (Object)#4
      [2] (Object)#5
      [3] (Object)#6
    uid = "89317E9C-3482-C356-35C4-2A345817AF6F"
  sort = (null)
  source = (Array)#2

该段SQL语句在查询管理器里里面的运行结果:


Flash的AS代码(as2.0)

import mx.rpc.RelayResponder;
import mx.rpc.FaultEvent;
import mx.rpc.ResultEvent;

import mx.remoting.debug.NetDebug;
import mx.remoting.PendingCall;
import mx.remoting.Service;

import mx.services.Log;

import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Label;

import mx.controls.RadioButton;
import mx.controls.RadioButtonGroup;

import TextArea.StyleSheet;

import mx.utils.Delegate;

class onlinePollQuestion extends MovieClip
{

        private var questionLabel:Label;

        private var answer0:RadioButton;
        private var answer1:RadioButton;
        private var answer2:RadioButton;
        private var answer3:RadioButton;
        private var radioGroup:RadioButtonGroup;
       
        private var voteButton:Button;

        var gatewayUrl = "http://localhost/flashservice/gateway.php";
        var componentPath = "GetPollInfo";

        function onlinePollQuestion()
        {
                trace("onlinePollQuestion()";
        }

        function onLoad()
        {                 
                trace("onLoad";
                trace("Calling: setupInitialDisplay";
                setupInitialDisplay();
                trace("Calling: getQuestionData";
                getQuestionData();
        }
       
        function setupInitialDisplay()
        {
                questionLabel.visible = false;
                answer0.visible = false;
                answer1.visible = false;
                answer2.visible = false;
                answer3.visible = false;
                voteButton.visible = false;
               
                voteButton.addEventListener("click", Delegate.create(this,onSubmitVote));
                //resultsButton.addEventListener("click", Delegate.create(this,onLastMonthResults));
               
        }
       
        function getQuestionData()
        {
                trace("getQuestionData()";
                var CFCService:Service = new Service(
                        gatewayUrl,
                        null,
                        componentPath,
                        null,
                        null);
                var pcendingCall = CFCService.get_data();
                //var pcendingCall = CFCService.getPollQuestion();
                pc.responder = new RelayResponder(this, "onGetOnlinePollQuestionResultData", "onGetOnlinePollQuestionResultFault" );
               
        }
       
        function onGetOnlinePollQuestionResultData( resultEvent:ResultEvent ):Void
        {               
                trace("onGetOnlinePollQuestionResultData()";
                trace("Result is "+ resultEvent.result);
               
                var records = 0;
                records += resultEvent.result.getNumberAvailable()
                trace("records: " + records)
                trace("totals:  " + resultEvent.result.getLength())

               
                if(resultEvent.result == "found"
                {
                        onCurrentResults();
                }else{
                        trace("getinfo is "+resultEvent.result.items[0]["vcPollQuestion"]);
                        onSetQuestionLabel(resultEvent.result.items[1]["vcPollQuestion"]);
                        questionLabel.visible = true;
                        voteButton.visible = true;
                        for(var i=0;i<resultEvent.result.items.length;i++)
                        {
                               
                                this["answer"+i].label = resultEvent.result.items["vcPollAnswer"];
                                this["answer"+i].data = resultEvent.result.items["intPollAnswerId"];
                                this["answer"+i].visible = true;
                        }
                }
        }

Flash的Trace结果:
onlinePollQuestion()
onLoad
Calling: setupInitialDisplay
Calling: getQuestionData
getQuestionData()
onGetOnlinePollQuestionResultData()
Result is [object Object]
records: 4
totals:  4
getinfo is undefined
onSetQuestionLabel()

我的几个问题:
1.如果php返回的是一个resource id,是否是正确的返回?
2。如果1成立,那么resource id是一个什么类型的数据?
3.如果1不成立,那么正确的返回应该是什么类型的数据?
4.如果1返回正确,是Flash as的处理的问题,能不能告诉我怎么处理这种数据格式?我是个Flash白痴,第一次接触AS编程

请大侠们帮我看看,非常感谢!

[ 本帖最后由 steelskin 于 2008-2-18 10:29 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP