dongyang9813 2010-09-04 01:15
浏览 35

将变量从Flash传递到PHP

Creating a flash project where users can visit the site, and turn off/on objects in a house (ie. lights, tv, computer, etc.) The next user who will visit the house in the website, will see what lights or house appliances were left on. Flash variables are passed to PHP, and those variables are saved in an XML file. (For testing to see what is being saved to the XML file, on each click --vars.xml opens.) In the vars.xml file, I see that the house objects that were last turned on--are saved in the XML file--BUT in the SWF file, ONLY one of the objects that are listed in the XML are turned ON. Only the last object that was clicked on would show ON--not all the objects in the XML file.)

package {
  import flash.display.MovieClip;
  import flash.events.MouseEvent;
  import flash.events.Event;
  import flash.text.*;
  import flash.net.*;

  public class House extends MovieClip {

    var request:URLRequest = new URLRequest("vars.xml")
    var loader:URLLoader = new URLLoader();


    // Constructor--------------------------------------------------------------------
    public function House()


    {

        loader.addEventListener(Event.COMPLETE, parseXML);
        loader.load(request); 

}

// function sendPhp ------------------------------------------------------------------
    function sendPhp():void
    {

        // send vars to php
        var request:URLRequest = new URLRequest("write_xml.php"); // the php file to send data to
        var variables:URLVariables = new URLVariables(); // create an array of POST vars


        for (var i:int=0; i<onList.length; i++) {
            variables["v"+i] = onList[i];
        }

        //variables['powerUsage'] = totalTxt.text;

        request.data = variables; // send the vars to the data property of the requested url (our php file)
        request.method = URLRequestMethod.POST; // use POST as the send method
        try
        {
            var sender:URLLoader = new URLLoader();
            sender.load(request); // load the php file and send it the variable data
            navigateToURL(new URLRequest("vars.xml"), '_blank'); //show me the xml
        } 
        catch (e:Error) 
        {
            trace(e); // trace error if there is a problem
        }
    }


// function parseXML ------------------------------------------------------------------

function parseXML(evt:Event)
{
    var xdata:XML = new XML(loader.data); // using E4x

    //xdata.child(0);

    for (var j:int=0; j<xdata.length(); j++) {
        onList[j] = xdata.child(j);

        for (var k:int=0; k<HouseObjects.length;k++) {
            //root[onList[j]].gotoAndStop(3);
            if (onList[j] == HouseObjects[k].name) {
                HouseObjects[k].gotoAndStop(3);
                //trace("tracing house objects"+ HouseObjects[k]);
                trace("onList[j]: " + onList[j]);
                trace("Array onList: " + onList);

            }

        }

    }

}



 } //end of class

} // end of package
  • 写回答

1条回答 默认 最新

  • dongpu8935 2010-09-05 13:39
    关注

    You actually don't need to put all this code here, and it's true that you should make your app more secure , especially after showing all this info! If your XML is not the problem , check the Actionscript part, particularly the parseXML() function.

    Are you able to trace the names of the components that are switched on? If yes , concentrate on what's happening in your loop. If your xml is fine, the problem is not passing data from PHP to Flash.

    I like the tree house! ;)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog